We're merging with GenerateBlocks! Learn more here.

[Resolved] Including more than one post type

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Including more than one post type

Tagged: 

Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #28150
    Joon
    Participant

    Thanks!

    That worked great!

    Is it also possible for the query to fetch posts from two different category taxonomies? The Events Calendar uses it’s own category taxonomy called “tribe events cat”. I tried to modify the query but came up short. This is what I came up with but it does not show anything… I guess this code requires that both of the arguments are true?

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
     if(16270 === (int)$settings['list_id']){
        $args['post_type'] = array('post','tribe_events');
    	$args['category_name'] = 'ajankohtaista';
    	$args['tribe_events_cat'] = 'ajankohtaista';
      }
      return $args;
    }, 15, 3 );
    #28156
    Joon
    Participant

    And I just want to say I really appreciate the help!

    The end result I’m trying to achieve is one where the user can add regular posts, that are automatically seen on the frontpage list. And when needed, they can choose a specific category for an event if they want the event to be seen in this same list.

    I realized that categories would be better suited to achieve this. The regular posts have a default category that is added to all posts. Events do not, but the user could add the event to a category if they want to add it to the frontpage.

    But the problem is that The Events Calendar uses their own taxonomy for their categories, so I’m not sure if you can achive this in a query like this?

    #28192
    elvin
    Moderator

    $args['tribe_events_cat'] = 'ajankohtaista';

    This won’t work. There’s no tribe_events_cat in the WP codex for wp_query.

    What you need is the taxonomy parameters: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters

    See my example code on taxonomy parameters here:
    https://wpshowposts.com/support/topic/show-posts-from-a-category-and-a-tag-2/#post-26833

    #28222
    Joon
    Participant

    Thank you!!

    add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
     if(16270 === (int)$settings['list_id']){
        $args['post_type'] = array('post','tribe_events');
    	$args['tax_query'] = array(
    			'relation' => 'OR',
    			array(
    				'taxonomy' => 'category',
    				'field'    => 'slug',
    				'terms'    => array( 'category_name' ),
    			),
    			array(
    				'taxonomy' => 'tribe_events_cat',
    				'field'    => 'slug',
    				'terms'    => array( 'category_name' ),
    			),
        	);
      }
      return $args;
    }, 15, 2 );
    

    This is the code I ended up with and it seems to do the job 🙂 If someone is using The Events Calendar and wants to pull single events to a WPSP list by adding it to a specific category, just rename the category_name in the code above.

    #28266
    Joon
    Participant

    So the code above works fine but I have a last question. Would it be impossible to prioritize some categories over others?

    95% time we will publish traditional posts/news but when we post stuff from these two other categories, it would be nice if we could “pin” these posts there for a while. Right now the only way to do that is to keep changing the date of these posts to keep them showing in the list. And because these are custom post types, the sticky feature in WordPress is not working. So would there be any to get post from these specific categories to “bypass” the traditional posts?

    There were some discussions here about prioritizing a specific category but I did not find a final solution…
    https://wpshowposts.com/support/topic/show-posts-in-current-category-and-specific-tag/

    #28279
    Joon
    Participant

    A “sticky featured tag” would also serve the same purpose..

Viewing 6 posts - 16 through 21 (of 21 total)
  • You must be logged in to reply to this topic.