WordPress.org

Ready to get started?Download WordPress

Forums

Advanced taxonomy queries (4 posts)

  1. trewknowledge
    Member
    Posted 2 years ago #

    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?

  2. trewknowledge
    Member
    Posted 2 years ago #

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

  3. Diana
    Expert e diva
    Posted 2 years ago #

    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.

  4. trewknowledge
    Member
    Posted 2 years ago #

    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');

Topic Closed

This topic has been closed to new replies.

About this Topic