Support » Plugins » Hacks » Advanced taxonomy queries

  • Hello. I have been scratching my head for a little while on this one.

    I have a custom post called “Slider” and a taxonomy called “Slider Categories”. Depending on the page I would like to display a slider based on the Slider Category.

    Here is my code:

    function slideshow($slider_category) {
    /* Query from the database. */
    $loop = new WP_Query(
    ‘post_type’ =>’slider’,
    ‘posts_per_page’ => -1,
    ‘orderby’ =>’ID’,
    ‘order’ =>’ASC’,
    ‘tax_query’ => array(
    ‘taxonomy’ => ‘slider_category’,
    ‘terms’ => array( $slider_category ),
    ‘field’ => ‘id’
    ) )

    And on my page template I have

    echo slideshow();

    Any suggestions on how to get it to work correctly?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I have the slider showing up, but not based on the category.


    You must set theme files for this.

    For post types I use archive-{post-type name}.php, you can link this using /?post_type=post-type-name, so all posts types in all taxonomies will show up.

    In post types, you don´t use categories, but always taxonomies, so you can set a taxonomy-{post-type taxonomy name}.php file for every taxo you have or just set one taxonomy.php file.

    What I was to accomplish is to have the custom post, which is slider with several images attached to a slider category, display on my page templates based on the slider category ID.

    I was able to accomplish that by calling in the function on my {page}-template.php file and using the function mentioned above.

    echo slideshow('7');

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Advanced taxonomy queries’ is closed to new replies.