0

I've setup a custom post type and a custom taxonomy for that post type, but I'm having one problem - on the custom taxonomy permalink pages, the content of the custom post that should be there is not being displayed. However, looking at the page source, I can see that there is a div that should contain the post content.

Any suggestions on how to get the entire content to be displayed?

Edit: The Custom Post Types UI plugin was used for the creation of the custom post types and the custom taxonomies.

Edit 2: Turns out it was a Thesis problem. Design Options > Display Options > Archives was set to "titles only", which kept the content of the posts from being displayed.

6
  • 1
    I think it's helpful you either name the specifics of the post type registration or paste the code you use to do so. Additionally the same for the custom taxoonmy on it then.
    – hakre
    Nov 21, 2010 at 23:20
  • Agreeing with hakre. It sounds like this has more to do with WP template tags than with custom post type and taxonomy related stuff. Nov 22, 2010 at 0:35
  • Good point - I noted in the OP that I used a plugin. Nov 22, 2010 at 3:44
  • For plugins, next to naming them, just leave a link so it's clear which one exactly. Just in case of a name clash. There are so many plugs, so just to be on the safe side for yourself and the ones who are answering.
    – hakre
    Nov 22, 2010 at 4:01
  • @tnorthcutt: FYI, when I visited the site with a mobile browser, the "test ring" post was visible. So I don't think there is anything wrong with the query. I don't see anything template-related in the Custom Post Type UI plugin code, so could you please give us a list of your template files, and the code of the most relevant?
    – Jan Fabry
    Nov 22, 2010 at 6:37

4 Answers 4

1

By default, a custom post type isn't included in the standard query. You'll need to manually create a query in your taxonomy page for that post type.

3
  • do you have update the permalinks after active your custom post type? WP must write hte permalinks new. Also you can use function flush_rewrite_rules() on the init of your custom post type, see this post for this topic wpengineer.com/2044/custom-post-type-and-permalink
    – bueltge
    Nov 17, 2010 at 1:03
  • I was afraid of that. Is there a programmatic way to do that, rather than writing a query for each entry in the taxonomy? I.e. my taxonomy is "types" (of jewelry), and I have rings, watches, bracelets, etc. Will I need a conditional statement for each type in my functions.php with a query for that particular type? Nov 17, 2010 at 4:05
  • In the future, please edit your previous answer to include updated information rather than creating a new answer!
    – EAMann
    Nov 22, 2010 at 14:59
3

Give this a shot, adding into your functions file

add_filter( 'pre_get_posts', 'include_tax_posts' );

function include_tax_posts( $query ) {

    if ( is_tax()  && false == $query->query_vars['suppress_filters'] )
        $query->set( 'post_type', array( 'post', 'page', 'YOUR_POST_TYPE' ) );

    return $query;
}
1
  • No dice. This is on the Thesis theme, FWIW. I did make sure I got the correct post type in there - at first it was wrong, but that removed the div where the content should be. I set it to the correct type, and the div is still there, but still with no content. Nov 17, 2010 at 15:47
0

Ok, did a bit of digging and it appears as though there is a ticket to fix this in the 3.1 release. Until then, you might wanna try using this plugin: http://wordpress.org/extend/plugins/simple-custom-post-type-archives/

The other option, since it's Thesis, is use their custom loop API and create a query to run on all pages being set from that taxonomy / post type.

4
  • The thing that bothers me is that empty div. That means it is looping through and returning the post, right? There's one for each post and it has the correct id="post_id", etc. Nov 22, 2010 at 4:53
  • @Norcross: Would you mind linking to the trac ticket?
    – t31os
    Nov 22, 2010 at 8:37
  • Here are two: core.trac.wordpress.org/ticket/13818 core.trac.wordpress.org/ticket/13816 There is a lot of back and forth about how they are going to be handled.
    – Norcross
    Nov 23, 2010 at 7:38
  • If this was an issue with WP not outputting custom post types on custom taxonomy pages, there wouldn't be any div with the post id there at all - you're just missing the content of the posts, while WP is at least acting like it's got posts to display on the custom taxonomy page...
    – somatic
    Nov 25, 2010 at 9:56
0

I don't know if this will help you where it looks like you are using a plugin to create custom post types and taxonomies (never had much like with those). This is what my developer did to get posts from a custom taxonomy to show up on a custom post page when the slugs match. Similar to what you're doing but technically in reverse...

In Functions.php...

Create custom post type to custom taxonomy relation

    global $post_tax;
    $post_tax = array(
        'store' => array('post' => 'stores', 'tax' => 'store'),
        'state' => array('post' => 'states', 'tax' => 'state')
    );

Register post types

function post_types_custom_init() {

global $post_tax;

register_post_type($post_tax['store']['post'], array('label' => 'Stores','public' => true,'show_ui' => true,'_builtin' => false, 'capability_type' => 'post','hierarchical' => true,'rewrite' => array('slug' => 'stores'),'query_var' => true,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes')) );

register_post_type($post_tax['state']['post'], array('label' => 'States','public' => true,'show_ui' => true,'_builtin' => false, 'capability_type' => 'post','hierarchical' => true,'rewrite' => array('slug' => 'states'),'query_var' => true,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes')) );

}

Hook into the init action and call create_post_type_taxonomies when it fires

add_action( 'init', 'create_beer_taxonomies', 0 );

Create taxonomies for their corresponding post types

function create_beer_taxonomies() 
{

global $post_tax;

// Add new taxonomy
  $labels = array(
    'name' => _x( 'Stores', 'taxonomy general name' ),
    'singular_name' => _x( 'Store', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Stores' ),
    'all_items' => __( 'All Stores' ),
    'parent_item' => __( 'Parent Store' ),
    'parent_item_colon' => __( 'Parent Store:' ),
    'edit_item' => __( 'Edit Store' ), 
    'update_item' => __( 'Update Store' ),
    'add_new_item' => __( 'Add New Store' ),
    'new_item_name' => __( 'New Store Name' ),
  );    

// Make it hierarchical (like categories) and assign to specific post types
  register_taxonomy($post_tax['store']['tax'],
    array('post',$post_tax['review']['post']),
    array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'stores-bp' ),
  ));

  $labels = array(
    'name' => _x( 'States', 'taxonomy general name' ),
    'singular_name' => _x( 'State', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search States' ),
    'all_items' => __( 'All States' ),
    'parent_item' => __( 'Parent State' ),
    'parent_item_colon' => __( 'Parent State:' ),
    'edit_item' => __( 'Edit State' ), 
    'update_item' => __( 'Update State' ),
    'add_new_item' => __( 'Add New State' ),
    'new_item_name' => __( 'New State Name' ),
  );

  register_taxonomy($post_tax['state']['tax'],
        array('post',$post_tax['beer']['review']),
    array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'states-bp' ),
  ));

}

In Template/Loop

function meta_loop_beers($queried_tax,$queried_term){
    //$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $queried_page = get_query_var('paged');
    $paged = $queried_page ? $queried_page : 1;

    $post_type = '';

    global $post_tax;
    foreach($post_tax as $relation){
        if( $relation['tax'] == $queried_tax ){
            $post_type = $relation['post'];
            break;
        }

    }


        $args=array(
          'post_type' => 'post',
          $queried_tax => $queried_term,
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
        );

        $my_query = null;
        $my_query = new WP_Query($args);

<PUT LOOP(S) HERE>

        wp_reset_query();


}

I believe* that is everything. You won't be able to copy-paste that code and get it working for you automatically but it will hopefully give you an idea as to how to get it to work. This was bleeding edge stuff at the time, completed about 6 months ago and I'm guessing there is a better implementation somewhere. Unfortunately, the site is still not live so nothing to show at the moment.

We also had to redirect (htaccess) those slugs for the taxonomies as we wanted those looking for the store (post type) and archive for the stores (taxonomy) to land on the same page where the 'profile page' of the store displayed both.

So the end result is that the archive page for domain.com/stores-bp/walmart will redirect to domain.com/stores/walmart.

Way too confusing! I can try to clarify where needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.