Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Ok so I have set up a custom content type: Event

I have then set up the custom taxonomies in hierarchical format for Event: Type

To display "event" posts in each "type", I'm using the template: taxonomy-type.php

I have then set up a widget "Custom Taxonomies Menu Widget" to list the "types" in one of my widget areas with a count for post in each type.

My issues:

Clicking one of them takes me to pages that don't match the "event" posts that should be there for that "type". (one of which, the party "type, shows no posts available even though I have some in that "type".

The count is not right for the posts in each category. (not that big of a deal compared)

share|improve this question
1  
Can we see some of your code please? Specifically, for the widget code you created (that seems to be where the problem is at based on your question) also taxonomy-type.php's code might be useful to look at. –  Jared Jan 21 '12 at 15:32
    
I'm using the plug-in "Custom Taxonomies Menu Widget". Could that be the issue? How can I just write my own? Code for the taxonomy-type.php: gist.github.com/1653479 –  Reuben Jan 21 '12 at 18:16
add comment

migrated from stackoverflow.com Jan 21 '12 at 15:20

This question came from our site for professional and enthusiast programmers.

1 Answer

Firstly, the 'future' status is for posts that are not yet published and should not be used to mark events that occur in the future.

(I would recommend storing the event's data in the post meta, and then query/order by that post meta field. See this question and this question)

Secondly, in your code you have these two lines:

$args = array( 'post_type' => 'event', 'posts_per_page' => 50, 'post_status' => 'future', 'order' => 'ASC' );
$loop = new WP_Query( $args );

These completely override the default WordPress query which attempts to find 'published' events from your database that match the taxonomy term. (keep in mind 'future' events/posts are not considered 'published'.)

Your $loop query attempts to query the database for any 'event' that is not yet published, and since this over-rides the original query, it should show the same for every taxonomy term.

But you don't see this... (sometimes you see that there are no events). This is because of the conditional:

have_posts();

This is checking if the orginal query had any posts (i.e. are there any published events in this taxonomy term). It is not checking your current query (are there any future events?). To check your $loop query:

$loop->have_posts();

How to merge rather than replace the query

So, above I've said that you are over-riding the query that WordPress automatically does (looks for published events for that term). To include the taxonomy-term request in your new query, use the following trick:

Replace the two lines of your query with:

$args = array( 'post_type' => 'event', 'posts_per_page' => 50, 'post_status' => 'future', 'order' => 'ASC' );
//Merge with default query
global $wp_query;
$args = array_merge( $wp_query->query,$args);
$loop = new WP_Query( $args );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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