Restrict Posts on Homepage Using Custom Taxonomy

Posted in: Newspaper
Post count: 14

We would like to restrict the inclusion of individual posts in the homepage blocks based on a Custom Taxonomy we set for each post.

Each block lists posts from 1 or more filtered categories. We want to use a Custom Taxonomy to include/exclude specific individual posts from the block.

We tried with the WordPress pre_get_posts hook, but it didn’t play well with the theme.

1) Please let us know if there is a different hook we can use or some existing function we can use instead.

2) I presume there must be some single common file, code segment or function where you call the Select for each post’s inclusion in the blocks.

If it exists, what is its name, where is it located, what line should we modify to add our custom select?

(We considered creating a category called “exclude” and putting -# in the category filter list, but that’s the opposite of how we want to work. We want all the articles initially excluded from the homepage, unless the taxonomy is explicitly checked to include that post.)

Thanks.

Post count: 23312

Hello SteveWA,

Unfortunately, our theme does not have any such an option that allows you to filter your posts by your Custom Taxonomy, sorry! The theme has been designed to use only Categories for filtering. If you want to achieve this feature, you should edit the td_data_source.php and add there some conditions to include this feature, like this -> https://www.screencast.com/t/URhMrsy2ivtn Notice that is not a simple task and if you are not some good coding skills and if you are not aware of the steps which are needed to take in this regard, please consider hiring a freelancer/developer to help you because we cannot provide custom work at the moment, sorry!

Thanks for the message!

Post count: 14

Wonderful. I got it to work:


if( is_front_page() ) { //only check taxonomy on frontpage

//init the array
$wp_query_args = array(
'ignore_sticky_posts' => 1,
'post_status' => 'publish',

// added this to only include posts with images in Blocks
// 'key' => '_thumbnail_id', // Not Working - probably because of the filler image

// added the below for Special Taxonomy Inclusion in Blocks
'tax_query' => array(
array(
'taxonomy' => 'editorial',
'field' => 'slug',
'terms' => 'home-page-article',
),
),

// End Special Taxonomy

);

} // end if-frontpage

else { //don't check if not frontpage

//init the array
$wp_query_args = array(
'ignore_sticky_posts' => 1,
'post_status' => 'publish',
);

} // if-!frontpage

Post count: 23312

Hello SteveWA,

I am glad that you could solve your problem and also, I will thank you for your solution. It may be useful for other users who are looking for this implementation.

Thanks for your message!

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.