admin管理员组

文章数量:1291013

I have succeeded at limiting the posts on my homepage to ones in a homepage category that I created by implementing the following in functions.php:

function limit_category( $query ) {
  if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'category_name', 'homepage' );
  }
}

add_action( 'pre_get_posts', 'limit_category' );

This works fine for posts of type post, but I also have some posts of custom type event that have the category slug set to homepage that are excluded from the homepage.

To display events I am doing this:

function include_events( $query ) {
  if( $query->is_main_query() && $query->is_home() ) {
      $query->set( 'post_type', array( 'post', 'event') );
  }
}

add_action( 'pre_get_posts', 'include_events' ); 

Is there a way I can also display event posts on the homepage when they have the homepage category?

本文标签: Apply category query clause to posts of custom type