0

I created a custom post type "projects" and then I created a taxonomy to categorize my projects "categoriesprojects".

I have dedicated a page that lists my projects randomly via WP_Query (archive-projets.php) in this way:

<?php 
    $projectslist = array(
      'post_type'=>'projets',
      'orderby' => 'rand'
    ); 
?> 
<?php $loop = new WP_Query($projectslist); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

So, if I launch mywebsite.com/projects, my projects are all listed, but now I would like to list projects related to a category only (taxonomy "categoriesprojects"), this way if I launch mywebsite.com/projects for example, I would like to have only posts in the "events" category.

0

You should try like

<?php 
    $projectslist = array(
      'post_type'=>'projets',
      'orderby' => 'rand',
      'tax_query' => array(
        array(
            'taxonomy' => 'categoriesprojects',
            'field'    => 'slug',
            'terms'    => 'events',
        ),
      ),
    ); 
?> 

Hope it will help you.

Please let me know if any query.

protected by Community Nov 7 '18 at 9:19

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.