• Hi, I am using event organiser for a site that includes multiple physical locations and events for each location. But on the individual “tenant” page they want to have a feed that includes both events and posts that pull from the appropriate categories.

    Like one tenant, the post category is 32 and the event category is 33.

    Is there a way to just write one query that will poll both post types for the appropriate category?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter justplaindoug

    (@justplaindoug)

    Because right now it seems like I can’t pull a specific category and if I take out categories then I can only get either events or posts. It’s really weird.

    Thread Starter justplaindoug

    (@justplaindoug)

    Current code:

    $custom_args = array(
    		'post_type' => array('event','post'),
    		'posts_per_page' => 4,
    		'paged' => $paged,
    		'category__in' => array('32','33'),
    'suppress_filters' => false
    	);
    Plugin Author Stephen Harris

    (@stephenharris)

    Hi Doug,

    A disclaimer: when pulling out events and posts, events will be treated like posts. I.e. the ordering will not by start date/time as posts do not have a start date/time.

    That aside, your query is not correctly formed. ‘category__in’ refers to the ‘category’ taxonomy (for posts) and not the ‘event-category’ taxonomy. In order to query multiple taxonomies you are going to have to use a ‘tax_query’: https://codex.www.ads-software.com/Class_Reference/WP_Query#Taxonomy_Parameters

    There’s an example for querying multiple taxonomies, but keep in mind the ‘relation’ in that example is set to ‘AND’ not ‘OR’. You’ll want to use ‘OR’ because an event cannot be in a category taxonomy and vice-versa.

    Thread Starter justplaindoug

    (@justplaindoug)

    Ignore- I got confused on my strings.

    Thread Starter justplaindoug

    (@justplaindoug)

    I figured it out. I’ll post it below if you want to add it to the knowledge base.

    But also, how can I sort by event date? Ideally I’d like to sort events by event date and posts by post date. I know, weird request. You know clients.

    Here’s the query to query by category dynamically (slug preferably)
    https://drive.google.com/open?id=0B9mWCVGBzWGjRXBmOU1tZW1rRVk

    Retrieving based on page or post slug-
    https://drive.google.com/open?id=0B9mWCVGBzWGjZjk4SDRkSDY0anM

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Combine post and event query on page?’ is closed to new replies.