Make a function to run only for CPTs

Before returning it’s result, get_permalink() applies one of 4 filters on the permalink it has generated, depending on the post_type of the post in question: post_link, when post_type == ‘post’ page_link, when post_type == ‘page’, via get_page_link() attachment_link, when post_type == ‘attachment’, via get_attachment_link() post_type_link, when post_type is not one of the above (i.e., a … Read more

WP Query—Relationship between two custom post types and their fields

I haven’t tested this but it SHOULD work. You’ll want to put it in the single-staff.php. You’ll have to add the details (actual query, post types, etc). $reports = get_posts(array( ‘post_type’ => ‘reports’, //use actual post type ‘meta_query’ => array( ‘relation’ => ‘or’, array( ‘key’ => ‘primary_contact’, // name of custom field ‘value’ => ‘”‘ … Read more

How to add extra input fields to CPT’s comment form?

If you have already found the filter inside the comment_form function, you are quite close. There is a filter called comment_form_default_fields which allows you to add extra input fields to the array of fields, which normally holds name, mail address and url. You use it like this (in your theme’s functions.php): add_filter (‘comment_form_default_fields’,’wpse270550_add_field’); function wpse270550_add_field … Read more

How to remove default tag and category options form a custom post type admin menu

Remove these lines: /* this adds your post categories to your custom post type */ register_taxonomy_for_object_type( ‘category’, ‘custom_type’ ); /* this adds your post tags to your custom post type */ register_taxonomy_for_object_type( ‘post_tag’, ‘custom_type’ ); They’re adding tags and categories to your post type, so of course they’re appearing.

Custom post type search with slug in URL

On the form, change action=”<?php echo site_url(“https://wordpress.stackexchange.com/”); ?>” To: action=”<?php echo esc_url( get_post_type_archive_link( ‘club_societies’ ) ); ?>” Where ‘club_societies’ is the slug of the post type you’re searching. That will set the form action to the archive URL, with the search parameters added, rather than the homepage with search parameters added.