• 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:

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

    And on my page template I have

    $slider_category=’7′;
    echo slideshow();

    Any suggestions on how to get it to work correctly?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Trew Knowledge

    (@trewknowledge)

    I have the slider showing up, but not based on the category.

    Hello,

    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.

    Thread Starter Trew Knowledge

    (@trewknowledge)

    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.