WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Types In index.php / Categories? (2 posts)

  1. StMarysWB
    Member
    Posted 2 years ago #

    Hello,

    We are running a Church Deanery website with WordPress. We have created a new Custom Post Type called 'event' / 'events' - and we are using the built in categories we use for normal posts with these CPT.

    I have been trying for quite a while to get this to work, but I would like the CPT to display on the index.php / Category / Archives page in the corresponding category. For example if I'm viewing the category 'Church Category One' - I want the 'event' CPT to display alongside the normal WordPress posts in this category.

    How do I do this?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with a query on your loop:
    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

    The event CPT 'event' posts needs to have the same category as the category page you are viewing to show up.
    example:

    <?php
    // on a category page
    $current_cat = get_query_var('cat');
    $args = array(
      'post_type' => array('post','event'),
      'cat' => $current_cat
    );
    query_posts($args);
    ?>
    <?php
    // on front page
    $args = array(
      'post_type' => array('post','event'),
    );
    query_posts($args);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic