• I am trying to display all author posts and coauthor posts on my authors.php page. Currently the single authors site is showing all the posts the he/she has written. But I am trying to display all the posts he/she has written as well as coauthored. I am currently using ACF to allow for the client to select the coauthor from a complied list of users who are authors. I am also using Timber. Currently this is what I have:

    author.php

    $coauthor_query = array(
      'post_type' => 'post',
      'meta_key' => 'coauthor',
    	'meta_query' => array(
    		'key' => $author,
    		'compare' => '='
    		)
    );
    
    $data['coauthors_posts'] = Timber::get_posts($coauthor_query);

    author.twig

    {% for post in coauthors_posts %}
    		{% include 'tease-coauthor.twig' %}
    	{% endfor %}

    so I have a query to select posts with a coauthor and have it display if it equals the author.

    any help would be appreciated.

    thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter novak1nt

    (@novak1nt)

    I have figured my issue out. So the problem was where I suspected it, in the wp_query selection. So I had the page echo out the sql query from the wp_query selection like so:

    $results = new WP_Query( $coauthor_query );
    echo $results->request;

    From this I was able to see that the ACF meta_key that I created(coauthor2) is displayed as a serialized Author ID. So here is the update to the query:

    $coauthor_query = array(
      'post_type' => 'post',
    	'meta_query' => array(
    		array(
    	    'key' => 'coauthor2',
    			'value' => serialize(strval($author->ID)),
    			'compare' => 'LIKE'
        )
    	)
    );

    Now on my Authors page. It will display all content posted by the author as well as anything he/she has coauthored.

Viewing 1 replies (of 1 total)

The topic ‘displaying all author posts and coauthor posts’ is closed to new replies.