Custom Post Type Metadata Not Saving

The primary issue is your save_post action isn’t firing because: add_action( ‘save_post’. ‘save_meta’, 10, 2 ); should be add_action( ‘save_post’, ‘save_meta’, 10, 2 ); You also have inconsistency between client-name and _client_name, but without seeing the field_value function, I’m not sure if that’s a problem or not. I would also use something more unique than … Read more

WP Query ‘posts_per_page’

You add the necessary parameters to ask only for posts with the relevant clinic ID. e.g. $q = new WP_Query( [ ‘post_type’ => ‘doctors’, ‘meta_key’ => ‘clinic_id’, ‘meta_value’ => get_queried_object_id(), ] ); However, you have a fundamental mistake in how the data structure is designed. Filterable fields are supposed to be stored as terms/taxonomies, not … Read more

Can’t save php string to a custom field

For some reason, your $subject variable is empty when you call get_the_content($post_id). When using save_post hook, you can pass additional arguments like $post and $update to your callback. For your case, you could use the second argument $post to grab the post contents. Code: function save_url_link( $post_id, $post ){ $pattern = “/(http|https):\/\/.*\/(.*)\.(mp3|m4a|ogg|wav|wma)/”; $subject = $post->post_content; … Read more

How to check if a PHP string is different than meta field?

I suppose it deleted the value when you had no URL in the content, so $audio_raw was empty. if ($audio_raw && get_post_meta( $post_id, ‘audio_url’, true ) != $audio_raw) { // update the meta field update_post_meta( $post_id, ‘audio_url’, $audio_raw ); } checks that $audio_raw isn’t false/null/empty and that $audio_raw isn’t the same as the string currently … Read more