• Resolved jaringobi

    (@jaringobi)


    Hi peeps,
    I’m trying to generate a custom query in the following fashion below (sidenote: I’m using Oxygen builder and I would like to integrate popular posts into their repeater element)

    and of course (PHP noobie), my code below doesn’t seem to work and I would appreciate if someone can point me in the right direction to make this work.

    
    function popular_posts_query( $query ) {
      global $post;
      if ( $query->query['post_type'][0] == 'post' ) {
        $popular_posts = array(
            'post_type' => 'post',
    
            'meta_key' => 'views_weekly',
            'orderby' => 'meta_value_num',
            'order' => 'DESC',
    
            'posts_per_page' => '3',
    	);
    
        $query->set( 'meta_query', $popular_posts );
        $query->set( 'orderby', 'views' );
        $query->set( 'no_found_rows', true ); 
      }
    }
    add_action( 'pre_get_posts', 'popular_posts_query' );
    
    ?>
    
Viewing 1 replies (of 1 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @jaringobi,

    I’m not familiar with Oxygen builder but the issue I see is that you’re using the parameters the wrong way. You’ll want to check the WP_Query documentation for more details, pay close attention to the Parameters section and then make the adjustments needed to get your code working.

Viewing 1 replies (of 1 total)
  • The topic ‘Question regarding creating a custom query’ is closed to new replies.