Custom post type term names with ampersand in the term name
Custom post type term names with ampersand in the term name
Custom post type term names with ampersand in the term name
Figured it out. I had to re-read the codex a lot to figure out that when you pass an array to update_post_meta it is serialized. By using maybe_unserialize() on the return value I was able to to get access to the values. Hope this helps some future searcher!
Use the wp_insert_post hook to run when a post is saved: function wpse_188435_save_movie_data( $post_id ) { if ( $imdb = get_field( ‘imdb_id’, $post_id ) ) { if ( $imdbInfo = get_imdb_connector_movie( $imdb ) ) { if ( isset( $imdbInfo[‘actors’] ) ) update_post_meta( $post_id, ‘actors’, $imdbInfo[‘actors’] ); if ( isset( $imdbInfo[‘languages’] ) ) update_post_meta( $post_id, ‘languages’, … Read more
You can create something similar to WYSIWYG link dialog by generating traditional HTML SELECT with OPTIONs as post items, and then make it more interactive (searchable,…) with Chosen jQuery library. It’s not as precise solution as that in editor, but it can be enough for you.
I ended up going with this type of solution. It seems to be working fine for me. I am open on ways to improve this code as it seems there is a better hook that could be used. function on_music_publish( $post_ID, $post ) { if ( $post->post_type != ‘music’ ) { return; } update_post_meta($post_ID, ‘_disable_fbc’, … Read more
Looking at the function update_woocommerce_term_meta(), you would recognize it just uses the wordpress function update_metadata(), which essentially means that woocommerce is using meta values, just like you do in you CPT. With this in mind, I wouldn’t think this procedure would slow down your site + your keeping compatibility by using existing functions. Also 20 … Read more
you have to use “esc_attr” in case your value contains a quote for exemple <?php echo esc_attr(get_post_meta(…));?>
You might be missing the ‘meta_key’ arg here: $args = array( ‘ignore_sticky_posts’=> 1, ‘meta_key’ => ‘wpl_location’, // here ‘post_type’ => ‘post_projects’, ‘meta_query’ => array( array( ‘key’ => ‘wpl_location’, ‘value’ => ‘Europe’, ‘compare’ => ‘IN’, ), ), ); source: https://codex.wordpress.org/Class_Reference/WP_Query (about three quarters down the page).
I agree with kraftner’s comments to the question. This is a bad idea and you stand a good chance of regretting it later. Store you data as granular post meta values. Everything is easier later on. However, add_post_meta() and save_post_meta() will serialize objects/arrays for you. You don’t have to do anything special: update_post_meta(1,’my_bad_idea’,array(‘i’,’will’,’regret’,’this’,’later’)); And get_post_meta() … Read more
Can’t save meta field value if the title not set