Navigation überspringen

[Gelöst] Post Type Restriction in WordPress Archives Appears to be Removed

This support ticket is created vor 3 Wochen, 1 Tag. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 6 Antworten, hat 1 Stimme.

Zuletzt aktualisiert von zacharyL vor 1 Woche, 4 Tage.

Assistiert von: Minesh.

Author
Artikel
#2787141
screenshot.jpg

I'm trying to restrict the post type in an archive of a custom taxonomy that is shared between two post types. When configuring the WordPress Archive with Toolset, there used to be an edit button in the archive selection options, but that doesn't appear to be present anymore (see attached image, where the left panel shows the archive I'm currently working on and the right panel shows a screenshot of the WordPres Archive settings when this feature was available as seen on one of my older tickets https://toolset.com/forums/topic/restrict-wordpress-archive-text-search-to-specific-post-type-again).

You can find the archive in question here: versteckter Link

The archive that I'm working on is intended for the Careers CPT that are categorized with the custom "Department" taxonomy. The Testimonials CPT also uses the Department taxonomy (for this application found here: versteckter Link), but they should not be appearing in the Department archives. Only Careers should appear here.

Any help in this manner would be greatly appreciated. Thanks in advance!

#2787146
screenshot.png

As an addendum, I just found that the edit button works on an archive that I had previously created for the generic posts. Can you explain why this feature is active for one archive configuration and not on another?

#2787278

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to follow the same workaround shared by Waqar with the reference ticket you shared:
- https://toolset.com/forums/topic/restrict-wordpress-archive-text-search-to-specific-post-type-again/#post-2672503

Does that help you to select the specific post types?

#2787380

The Edit button isn't even present in this or any other WordPress Archive I try to associate with the Department taxonomy (see here: versteckter Link), so Waqar's advice is unhelpful here.

The configuration of the taxonomy doesn't appear to be any different than what I typically configure for custom taxonomies so I don't quite know what's going on here when on the same site the Edit button is available for selection (as seen in my previous screenshots) in another WordPress Archive configuration for a different post type and taxonomy.

Edit: As an addendum, I moved the Department archives into a separate new WordPress Archive configuration, not because of this ticket, but simply because the design of the site called for an altered layout for the Department archives. I still have a need to filter out the Testimonials posts in the main post feed, however, as you can see in this example: versteckter Link

#2788045

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Ok - you will have to understand how it works.

- For "Standard Archives":
you can control the post types.

- For "Custom Post Archives":
The post type control is not required as the archive itself for specific post type. For instance, if you have post types "Students" and "Classes" and when you create post type archive for post type "Students" it will displays the posts belongs to "Students" post type. Its by design of WordPress in post type archive we should not include posts belongs to another post type. So with this type post type control is not required.

- For "Taxonomy Archives":
The post type control is only available for native taxonomies like "category" andt "tags".

For custom taxonomy like "Departments" etc..et.. when you set the archive to display specific taxonomy, it will automatically set the archive to display posts from post types where the taxonomy is assigned.

For instance, if you have custom taxonomy X and you attach this X taxonomy to post type A and post type B, when you create a taxonomy archive for taxonomy X, it will automatically set the archive to display posts from post type A and B.

If you want to control the posts type for your taxonomy archive, then you will have to use the standard WordPress hook "pre_get_posts":

For example:
For instance, deparntment taxonomy is assigned to Students and Classes post type. By using the following code it will restrict the department taxonomy archive to display posts from only Student post type.

add_action( 'pre_get_posts', 'func_exlude_posttype_from_taxonomy_archive', 99,1 );
function func_exlude_posttype_from_taxonomy_archive( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_tax( 'department' ) ) {
  
//// set posts from what post types you want to display 
  $query->set("post_type","student");
  			
 }
}
#2788105
Screenshot 2024-12-13 at 11-05-20 Company Drivers Archives Barnhart Inc.png

So by virtue of having a custom taxonomy associated with multiple post types, I won't be able restrict the post type in the WordPress Archive configuration?

Well, it looks like the code you provided appears to be working, so that helps out a lot. Thanks for your assistance!

#2788474

Minesh
Supporter

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

So by virtue of having a custom taxonomy associated with multiple post types, I won't be able restrict the post type in the WordPress Archive configuration?
===>
yes - thats true.

Glad to know that solution I shared help you to resolve your issue.

#2788749

It is resolved, thank you for your help in this matter.