Question regarding creating a custom query
-
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)
Viewing 1 replies (of 1 total)
- The topic ‘Question regarding creating a custom query’ is closed to new replies.