Ask your WordPress questions! Pay money and get answers fast! (more info)

Author template - separate CPT's by custom tax term for $curauth WordPress

Good day,

I have a site with the following features:
- User generated, using custom Roles and Capabilities
- Several CPT's
- Several Custom Taxonomies and term types

for the purpose of this enquiry, these need to be used: Role: 'photographer' | CPT = 'photograph' | Taxonomy group = photograph-subject | Terms i.e. Abstract, Landscape etc etc (approx 18).

On my custom Author template, i want to output the following for each author:
- A list of Posts posted in CPT 'photograph' and separated/categorized by the term types i.e Abstract, Landscape etc etc.
- If the CPT has been assigned to more than one term to the post needs to show up for each result.

Basically need to output the following:

<h2>Term 1</h2>
<li>Photograph cpt, term 1, post 1</li>
<li>Photograph cpt, term 1, post 2</li>
<li>Photograph cpt, term 1, post 3</li>

<h2>Term 2</h2>
<li>Photograph cpt, term 2, post 1</li>
<li>Photograph cpt, term 2, post 2</li>
<li>Photograph cpt, term 2, post 3</li>

Let me know if anything is unclear.


Answers (2)


Yakir Sitbon answers:

Are you know this class:

lawless comments:

Yes i do.

I need a SQL query function, that queries the database against a author id i.e. $curauth->ID for posts that they have posted under a specific Taxonomy group (photograph-subject) terms and only return those posts from photograph cpt separated by the terms.

Yakir Sitbon comments:

I do not understand you.
You can get current author by post, but no by terms.

lawless comments:


I need to get posts (Photograph CPT) for $curauth by the terms.

So If author ID has posts assigned to Photograph CPT under the term Abstract, then display it. and do that for each term.

I am basically wanting to get all the terms for posts by an author.


Dbranes answers:

You can try something like this:

$currauthor_id = get_the_author_meta('ID');
$terms = get_terms('photograph-subject', array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
) );
foreach ( $terms as $term ) {
$myquery = new WP_Query( array(
'author' => $currauthor_id,
'post_type' => 'photograph',
'photograph-subject' => $term->slug,
'posts_per_page' = > -1,
<h2>Term: <?php echo $term->name; ?></h2>
<?php if ( $myquery->have_posts() ){
while ( $myquery->have_posts() ) : $myquery->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; } ?>
<?php wp_reset_postdata();?>
<?php } ?>

lawless comments:

Great stuff that worked.

Thank you

Dbranes comments:

ok great, please vote to close this question if this solved your problem, thanks ;-)