Tagged: is_author, main query, pre_get_posts
- This topic has 1 reply, 2 voices, and was last updated 6 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
December 6, 2015 at 12:40 am #5239
AnthonyMemberI am trying to alter the
main_queryforis_author()in apre_get_posts()function. Essentially I want to grab the posts it normally would grab (posts by the author) but also grab posts with that author id which is the value for meta custom value. In this case `user_mediaographer’Here is my stab at it, but its still not yielding any posts:
function author_and_mediaographers_loop( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( $query->is_author() && $query->is_main_query() ) { // $query->set('ignore_sticky_posts', true); // $query->set( ); $query->set( array( 'meta_key' => 'user_mediaographer', 'meta_value' => true, // 'meta_compare' => '>=' )); // $query->set( 'meta_key', 'user_mediaographer' ); // $query->set( 'meta_value', true ); } } add_action( 'pre_get_posts', 'author_and_mediaographers_loop' );As it is written, it doesn’t function but I can see if I did, it would only grab the posts that had the
meta_valuewith the author ID. But I don’t see how what I have is adding to the main_query. Can anyone shed a little light here? -
December 7, 2015 at 12:36 pm #5251
SteveKeymaster@anthonyabraira– Though we love to help as much as possible, we’d appreciate if you could keep your questions Piklist related. This is a general WordPress question.
-
-
AuthorPosts
- You must be logged in to reply to this topic.