1

How can I fix this, I get an error 404 when I access the second page of post-type:

web.site/clipuri/2012/

web.site/clipuri/2012/page/2/

register_post_type('clip', array(   'label' => 'Clip','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => true,
'rewrite' => array('slug' => ''),
'query_var' => true,'has_archive' => true,
'menu_position' => 5,'supports' => array('title','editor','custom-fields','category', 'post_tag',),
'labels' => array (
'name' => 'Clip',
  'singular_name' => 'Clip',
  'menu_name' => 'Clip',
  'add_new' => 'Add Clip',
  'add_new_item' => 'Add New Clip',
  'edit' => 'Edit',
  'edit_item' => 'Edit Clip',
  'new_item' => 'New Clip',
  'view' => 'View Clip',
  'view_item' => 'View Clip',
  'search_items' => 'Search Clipuri',
  'not_found' => 'No Clip Found',
  'not_found_in_trash' => 'No Clip Found in Trash',
  'parent' => 'Parent Clip',
),) );

register_taxonomy("clipuri","clip", array("hierarchical" => true, "label" => "Cat Clip", 'show_ui' => true, 'query_var' => true, "singular_label" => "clipuri", "rewrite" => true, 'with_front' => true));

In the theme I use:

<?php global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'clip')  );
query_posts( $args ); ?>

<div class="nav">
<?php if(function_exists('wp_paginate')) {wp_paginate();} ?>
</div>

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
3
  • What template is the theme code from? Sep 29, 2012 at 0:14
  • taxonomy-clipuri.php
    – Batman
    Sep 29, 2012 at 0:19
  • Ok, so on your taxonomy archive you need to show 2 different post types? Let me try to work something up with pre_get_posts Sep 29, 2012 at 0:25

1 Answer 1

0

For modifying the main query, I think it is best to take advantage of the pre_get_posts action.

When using pre_get_posts the $query variable is passed "by reference" which means we can directly manipulate the $query object with the shortcut functions such as set_query_var. Remove the query code from your taxonomy template, and try the following in your functions.php:

function wpa_66609( $query ) {
    if ( is_tax('clipuri') && is_main_query() ) {
        set_query_var( 'post_type', array('post','clip' ) );
    }
}
add_action( 'pre_get_posts', 'wpa_66609' );

If that doesn't work, I'll try to debug it.

1
  • Excellent! I was going to ask you some more questions after visiting your link, but now I don't have to. Cheers. Sep 29, 2012 at 0:35

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.