- This topic is empty.
-
AuthorPosts
-
April 17, 2013 at 10:38 pm #44200
jacorre
ParticipantHi everyone,
I think I’ve exhausted all I can do to figure this one out. I’ve also tried searching for answers and nothing has worked. This is in relation to WordPress.
I have a custom post type of _project_ and a custom taxonomy of _projectcat_. I want an archive for my project category taxonomy. So I created a template file _taxonomy-projectcat.php_.
Am I correct in thinking that I do not have to do any WP_Query or query_posts calls on that template in order to get any posts to appear? Right now if I just keep the normal loop, I get no posts.
If I introduce a query_posts including arguments for post_type=project and projectcat=$term->slug, I see posts, but if I go to page 2 I get a 404?
I have public, publicy_queryable, and has_archive set to true when registering the custom post type.
Please tell me I’m missing something stupid! Or is there a bug?
April 18, 2013 at 1:32 am #132245pixelgrid
Participantthere are a few thing that could work
make sure you include a paged variable in your query string to the WP_Query
you can find the paged variable like this
$paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1;
also in custom queries sometimes a hack is needed for the pagination to work,change the value of the wp_query global to the value of your query .
$temp = $wp_query;
$wp_query = null;
$wp_query = $my_query;use the structure
have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
and after the endif place your pagination links and reset the global query object with the temp you have stored
php next_posts_link ()
$wp_query = $temp; ?>April 18, 2013 at 9:50 am #132311jacorre
ParticipantI’m just confused that everything I’ve read about the custom taxonomy template leads me to believe I don’t need to use WP_Query or query_posts. All I need to do is copy the archive.php template file and name it taxonomy-{taxonomy-slug}.php.
Thanks @pixelgrid, I’ll have to give that a try.
April 18, 2013 at 8:01 pm #132374jacorre
Participant@pixelgrid I tried using WP_Query and I am getting what I expect in terms of seeing the posts I expect, but yes the previous/next links for pagination are not appearing. I’m not sure I understand your suggestion for the pagination hack? If I am using the following:
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$term = get_term_by(‘slug’, get_query_var(‘term’), get_query_var(‘taxonomy’));
$project_args = array(
‘post_type’ => ‘project’,
‘posts_per_page’ => 2,
‘paged’ => $paged,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘projectcat’,
‘field’ => ‘slug’,
‘terms’ => $term->slug
)
)
);
$projects = new WP_Query($project_args);
if ($projects->have_posts()) : while ($projects->have_posts()) : $projects->the_post(); $cnt++; ?>How would I apply your hack? I appreciate the help!
April 18, 2013 at 8:33 pm #132375jacorre
ParticipantOk talk about pulling my hair out! I went back to the standard loop but this time I changed the exclude_from_search from true to false when registering the custom post type. The custom posts show up and the paging is working fine. AHHHH! Thanks for the help!
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.