Support

Account

Home Forums General Issues Show all posts WITHOUT relationship link to specific posts

Helping

Show all posts WITHOUT relationship link to specific posts

  • I’m trying to create a custom query in my template file that shows all posts that are by any other author than the ones I specify. It’s set up to do the query against an ACF Relationship field that connects an author with a post. I have reworked this from a custom query that shows all posts by a specific author. That one works as desired, but my “all posts by anyone else” query does not.

    Can anyone help me sort this out?

    
    /*
      Show all posts WITHOUT relationship link to specific posts
    */
    
    $authorID1 = 128; // First Author
    $authorID2 = 126; // Second Author
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    
    $thePosts = new WP_Query(array(
    	'post_type'        => 'post',
    	'posts_per_page'   => 10,
    	'meta_query' => array(
    		'relation' => 'OR', // Use 'OR' for posts matching either author ID
    		array(
    			'key' => 'author',
    			'value' => $authorID1,
    			'compare' => 'NOT LIKE',
    		),
    		array(
    			'key' => 'author',
    			'value' => $authorID2,
    			'compare' => 'NOT LIKE',
    		),
    	),
    	'order' => 'DESC',
    	'orderby' => 'date',
    	'post_status' => 'publish',
    	'paged' => $paged,
    )); 
    
  • This really seems like it should work. Is it close?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.