$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>List posts that have the current url taxonomy|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

List posts that have the current url taxonomy

matteradmin10PV0评论

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/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/projects for example, I would like to have only posts in the "events" category.

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/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/projects for example, I would like to have only posts in the "events" category.

Share Improve this question edited Nov 6, 2018 at 12:45 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Nov 6, 2018 at 1:45 FloriaanFloriaan 1 0
Add a comment  | 

1 Answer 1

Reset to default 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far