WordPress.org

Ready to get started?Download WordPress

Forums

Showing Custom Post Types filtered by category (1 post)

  1. JohnPantz
    Member
    Posted 1 year ago #

    Hi,

    I'm currently running the latest version of wordpress and have begun building a custom site starting off with Bones as a starter.

    I've made a custom post type called artist and have enabled categories within it, there are two categories to filter. Resident and Guest.

    I'm using the following code to display all the posts from the custom post type, but can't get it to filter by category.

    <?php
    
    $args = array(
    'post_type' => 'artist',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    );
    echo '<ul id="onpagemenu">';
    $posts = new WP_Query( $args );
    while($posts->have_posts()) : $posts->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('artist-thumb'); ?></a><br />
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile;
    echo '</ul>';
    wp_reset_query();
    ?>

    I've tried using something like 'category_name' => 'guest' in the $args_guest array, but it doesn't change the outcome.

    Does anybody have any suggestions on how I could get this to work?

    Would be much appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic