I need to add a filter to prepend the term ‘National – ‘ to the post title if the post is tagged to multiple states

Your “states” appear to be terms in a custom taxonomy. In the code below I’ve assumed the taxonomy’s name is my_state; you’ll need to make sure that’s updated to match the actual taxonomy name. add_filter( ‘the_title’, function( $title, $id ) { // Gets the list of ‘states’ the post belongs to. $states = wp_get_post_terms( $id, … Read more

Get Comma Seperated Taxonomy Linked Terms and Last Child Separated By “&” Instead Of Comma

What you’re asking is a generic PHP/programming question, and this: “It links all terms to the last term link only“, is because your code clearly is attaching the link (i.e. the last value assigned to $term_link) to the entire list ($entry_terms), i.e. echo ‘<a href=”‘ . esc_url( $term_link ) . ‘”>’ . $entry_terms . ‘</a>’. … Read more

Custom Post Types not queried in Custom Taxonomy archives or Native archives

Tags shared by CPTs and standard posts return only the latter, and topics archives or tag archives with only CPTs assigned return empty. As for the tag archives, that’s a default behavior in WordPress core, i.e. tag (post_tag taxonomy) and category (category taxonomy) archives will only query posts where the type is post. However, the … Read more

A function to add arguments to a taxonomy

Use the filter register_taxonomy_args to manipulate the arguments used for registering the taxonomy just before it is registered: function wpse_406824_vendor_taxonomy_args( $args, $name ) { if ( $name === ‘dc_vendor_shop’ ) { $args[‘show_in_rest’] = true; $args[‘query_var’] = true; $args[‘show_ui’] = true; } return $args; } add_filter( ‘register_taxonomy_args’, ‘wpse_406824_vendor_taxonomy_args’, 10, 2 ); You’ll need to place this … Read more

WordPress bulk category select when publishing post

The default function that renders the categories meta box is post_categories_meta_box – it doesn’t have any internal hooks we can use to inject our own HTML, so let’s create our own meta box handler and just use the function internally: function wpse_406861_post_categories_meta_box( $post, $args ) { post_categories_meta_box( $post, $args ); echo <<<HTML <label> <input type=”checkbox” … Read more

get_term_by seems to be failing

get_term_by() returns object by default. Which should end up in Catchable fatal error: Object of class stdClass could not be converted to string if you try to echo it. Likely you have errors suppressed. Try var_dump( $term ); instead of echo.