Hierarchical Taxonomy Terms Select Menu Output with selected=”selected” Set

In each foreach loop, you’re setting the first item’s ID as the value for $selected which will obviously match the ID of the first item. Before running any of the foreach loops fetch the stored value from the DB then use that for the comparison. global $wpdb; $selected = $wpdb->query( “SELECT something FROM $wpdb->table_name” ); … Read more

Display post titles that match string in post content

The problem is that you are matching the title string in the entire content as whole and not word by word. e.g. if your title is ‘blog’ and content contains the word ‘blogging’, it will still match and pull ‘blog’ from ‘blogging’. So, you can compare them word by word by exploding the content as … Read more

Adding taxonomy terms based on custom field

You should be able to just the following: Just a couple of things to note: By using get_term_by() instead of term_exists(), you hit the term cache instead of the database for every retrieval of the term object. /** * Set terms for the given post type based on a meta value. */ function wpdocs_set_terms_for_post_types() { … Read more