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.

I have a number of regular posts and pages in a regular category called "Featured". I have also installed a plugin called "Event Organizer" that creates its own custom post type called "Event" and has its own interface for creating plugin-specific categories.

Anyways, what I've created is a basic highlight slider using a query to pull in the featured category posts and pages (I enabled categories in my pages) as well as the event posts. This is the query:

$args=array(
  'post_type' => 'any',
  'showposts' => $featured_num,
  'order' => 'DESC',
  'tax_query' => array(
    'relation' => 'OR',
    array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => 'featured'
    ),
    array(
        'taxonomy' => 'event-category',
        'field' => 'slug',
        'terms' => 'featured-event',
    )
    )
  );
$my_query = new WP_Query($args);

The problem is that everything works fine on my local testing environment but absolutely refuses to work on my web host. In my local testing environment both the "featured" posts and pages are pulled up AS WELL AS the event custom posts. On my web host only the event posts show. If I switch "post type" to array('post','page') I get the featured posts and pages but lose the event posts.

share|improve this question
3  
have you tried array( 'post', 'page', 'event' )? look at the query on both setups to see if there are differences- add print_r( $my_query ) and inspect the SQL generated in both cases. –  Milo Mar 24 '13 at 5:34
1  
Add debugging information please. –  s_ha_dum Mar 24 '13 at 13:35

2 Answers 2

These scenarios become much easier if you use plugins like wordpress posts2posts to establish a relation (for example featured posts to this page) and then pull them easily in the context

http://wordpress.org/extend/plugins/posts-to-posts/

Hope it will help you write effective code :)

share|improve this answer

Use 'post_status' => array('featured','publish') and 'post_type' => array('post','page','event')

but if Event post type slug is 'event'

Also it's a known issue that 'post_type' => 'any' doesn't work!

share|improve this answer
    
I'm looking at /wp-includes/query.php at lines 2897-2902 and see that it does indeed officially support using the "any" post_type; if supplied, it enumerates through known post types using get_post_types() and would potentially fail if it couldn't find any (hence the AND 1=0 SQL it injects). This said, I've never tried this and didn't even believe this was possible using standard WP queries. –  Justin Bell Oct 4 at 15:02

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.