• Hello,

    I’m trying to return a list of events and posts together and I’ve hit a bit of a wall. Hoping some kind person can help me out.

    I have a post category called novita (num 15) and an event category called novita (which, oddly also seems to be category id 15). However, I understand that events need to be queried using event_category rather than event ids. So…

    I want to return where (post_type = ‘post’ and category = ’15’) or
    (post_type = ‘event’ and ‘event_category’ = ‘novita’)

    So I’ve been playing around with boolean things in the args, but even without worrying about the category filter for a bit,

    <?php
    
    $args = array(
    	'relation' => 'OR',
    		array('post_type' => 'post'),
    		array('post_type' => 'event'));
    
    	$my_query = new WP_Query( $args );
    
    //  Returns just posts
    
    	$my_query = new WP_Query( array( 'post_type' => array( 'post', 'event' )));
    
    // Returns posts and events as expected

    Any advice much appreciated.

    https://wordpress.org/plugins/events-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    Thread Starter jeremy2805

    (@jeremy2805)

    Thanks but I can’t see what you’re suggesting that I try. My problem is that maybe I’m doing to ‘relation’ => boolean thing wrong and those two threads (and the threads pointed to from them) are about dates.

    Sorry to be a pain, but could you elaborate?

    Thanks.

    I’m not sure I follow what you’re trying to do. Do you want to list all posts in category 15 with all events in event category 15?

    Thread Starter jeremy2805

    (@jeremy2805)

    Yes, but I don’t think you can use category numbers for events (happy to be told differently) so it’s all posts where cat = ’15’ and all events where event-categories is ‘novita’ (the stub).

    I’ve now got to the point where I can get them using separate wp_query’s but not a merged result set (which I’m hoping to sort by post date.)

    I’ve been trying to create a tax_query args array all afternoon. It’s doing my head in.

    <?php
    
    	$args = array(
    		'post_type' => array( 'event' ),
    		'event-categories' => 'novita',
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'posts_per_page' => 12
    	); 
    
    	$my_query = new WP_Query( $args );
    
    	while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    		<div>
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<div class="excerpt"><?php the_excerpt(); ?></div>
    	</div>
    	<?php endwhile;
    
    	$args = array(
    		'post_type' => array( 'post' ),
    		'cat' => '15',
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'posts_per_page' => 12
    	);
    
    	$my_query = new WP_Query( $args );
    
    	while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    		<div>
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<div class="excerpt"><?php the_excerpt(); ?></div>
    	</div>
    	<?php endwhile;
    
    ?>

    Thread Starter jeremy2805

    (@jeremy2805)

    So with the meta_query disabled, the query returns all events and posts.

    With the meta_query enabled, it returns nothing.

    <?php
    
    	$args = array(
    		'post_type' => array( 'event', 'post' ),
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'posts_per_page' => 12
    /*		'meta_query'             => array(
    		  	'relation' => 'OR',
    			array(
    				'key'       => 'cat',
    				'value'     => '15',
    				'compare'   => '='
    			)
    			array(
    				'key'       => 'event-categories',
    				'value'     => 'novita',
    				'compare'   => '='
    			)
    		) */
    	); 
    
    	$my_query = new WP_Query( $args );
    
    	while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    		<div>
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<div class="excerpt"><?php the_excerpt(); ?></div>
    	</div>
    	<?php endwhile;?>

    I tried it with just the cat=15 bit in, and it returned nothing.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Mixed Events/Posts wp_query…’ is closed to new replies.