2

I have this code:

// Posts or Portfolio Widget
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    // Modify the posts query here
} );

source: https://developers.elementor.com/custom-query-filter/

and need to call my_custom_filter query to sort by this:

get_option( 'stats_cache' );

which would array something like:

array(
    ['7375996b7a989f95a6ed03ca7c899b1f'] => array(
        [1353440532] => array(
            [0] => array(
                ['post_id'] => 0
                ['post_title'] => 'Home page'
                ['post_permalink'] => 'http://www.example.com/'
                ['views'] => 1132
            )
            [1] => array(
                ['post_id'] => 4784
                ['post_title'] => 'Hello World!'
                ['post_permalink'] => 
                ['views'] => 493
            )
            /* till item [9] */

or this (I am hosted on wp and run jetpack --- this is preferred actually):

if( function_exists( 'stats_get_csv' ) ) {
    $top_posts = stats_get_csv( 'postviews', 'period=month&limit=30' );
}

which would return this:

array(
    [0] => array(
        ['post_id'] => 0
        ['post_title'] => 'Home page'
        ['post_permalink'] => 'http://www.example.com/'
        ['views'] => 6806
    )
    [1] => array(
        ['post_id'] => 8005
        ['post_title'] => 'Hello World!'
        ['post_permalink'] => 
        ['views'] => 1845
    )           
    /* till item [29] */

source: How to query the number of view counts for a post in Wordpress JetPack?

I have created the custom query ID -

( 'elementor/query/my_custom_filter', function( $query )

but I am not sure how to use these 2 functions:

  1. get_option( 'stats_cache' );
  2. if( function_exists( 'stats_get_csv' ) ) { $top_posts = stats_get_csv( 'postviews', 'period=month&limit=30' ); }

or where/how to insert them here:

// Posts or Portfolio Widget
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    // Modify the posts query here
} );

for the query to work.

I have tried to paste the jetpack function inside but that didn't work and I have tried to 'orderby', $top_posts or call $top_posts = $query but no success and a bunch of other stuff but nothing worked, for sure not doing something right here.

chaimsem
  • 41
  • 9

0 Answers0