Viewing 1 reply thread
  • Author
    Posts
    • #5239
      Anthony
      Member

      I am trying to alter the main_query for is_author() in a pre_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_value with 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?

    • #5251
      Steve
      Keymaster

      @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.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.