Hot answers tagged

2

I tested your all attempts in a shortcode: function add_test_shortcode() { global $wpdb; global $post; $post_ID = $post->ID; $wpdb->show_errors = true; $result = $wpdb->get_var('SELECT meta_value FROM '.$wpdb->postmeta.' WHERE meta_key="my_test" AND post_id=' . $post_ID); return $result; } add_shortcode( 'test', 'add_test_shortcode' ...


2

Q1 Yes, you can store serialized arrays as a single meta key, eg: update_post_meta( $post_id, 'my_items', array( 1, 2, 3, 4 ); Furthermore, you can store multiple values against a single meta key, eg: add_post_meta( $post_id, 'my_items', 1 ); add_post_meta( $post_id, 'my_items', 2 ); The latter is preferred because meta queries can be more efficiently ...


1

You need to get the title for each post ID in your array. The straightforward way is this: $procedure_title_list = array(); $procedure_list = get_post_meta($patient_story->ID, 'Procedure', false); foreach ( $procedure_list as $procedure ) { $procedure_title_list[] = get_the_title( $procedure ); } echo implode( ', ', $procedure_title_list );


1

Are you outputting the saved data to the edit post page before saving the post? If not you may be getting a empty $_POST['collection-topics'] data and then saving empty or null data. I would do a check before doing add_post_meta() if ( empty($_POST['collection-topics']) ) return;


1

This is how meta_key/_values work. How you store your values is case sensitive. Example meta_key = 'foo' and meta_value = 'Bar' Would return the result you are looking for: $posts = new WP_Query( 'post_type=post&meta_key=foo&meta_value=Bar' ); Would not return the result you are looking for: $posts = new WP_Query( 'post_type=post&meta_key=...


1

Here's the solution update wp_postmeta set meta_key = 'theme2035_embed' where meta_key = 'video'


1

You should always use update_post_meta() function because if the term doesn't exist it will make a call to the add_post_meta() automatically. The same goes for update_user_meta(). Example if you want to add the meta "City" but you don't have it in the db you simply make a update_post_meta($city) and in $city you need the post_id and the new value for city....


1

Your code for scheduling event isn't correct, here is the correct one: function hits_set_zero_schedule() { if ( ! wp_next_scheduled( 'hits_set_to_zero') ) wp_schedule_event( time(), 'daily', 'hits_set_zero' ); } add_action( 'wp', 'hits_set_zero_schedule' ); function hits_set_zero_func() { delete_post_meta( $post_id, 'post_views_count', true ); } ...



Only top voted, non community-wiki answers of a minimum length are eligible