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.

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