New answers tagged

0

I had this problem and this is how I solved it : In my case, I wanted to add an array to the existing serialized data : I wanted to add the new array data posted using Ajax to the existing meta_key. Note : Existing meta_key is 'accordions' function save_new_data(){ // Step 1: get the data you want to add (can be from an ajax post like my case) ...


0

$args = array( 'post_status' => 'publish', 'posts_per_page' => '150', 'cat' => $cat_id, 'order' => 'DESC', 'meta_query' => array( 'relation' => 'AND', 'popularity' => array( 'key' => 'popularity', 'orderby' => 'meta_value_num' ), 'gone' => array( 'key' => 'gone', 'value' => '1' ) )); ...


0

That is easy, you are trying to update the wrong value. Please replace the following if ( isset($_POST['package']) ) update_post_meta($post_id, 'zon_package', esc_sql($_POST['zon_package']) ); if ( isset($_POST['zon_phone']) ) update_post_meta($post_id, 'phone', esc_sql($_POST['phone']) ); With this: $zon_package = ''; $zon_phone = ''; if ( isset($...


0

As @fischi pointed out, it should be safe to delete empty values because get_post_meta() returns the same value for non-existent and empty meta keys, unless you somehow rely on the keys being set when fetching all metadata at once. WP 3.1 introduced the filters add_{$meta_type}_metadata and update_{$meta_type}_metadata that you can use to clean up empty ...


0

Please try to use following code add_filter( 'aws_title_search_result', 'my_aws_title_search_result', 10, 3 ); function my_aws_title_search_result( $title, $post_id, $product ) { $text1 = get_post_meta( $post_id, '_tyre_size_field', true ); $text2 = get_post_meta( $post_id, '_load_speed_field', true ); $text3 = get_post_meta( $post_id, '...


0

I had one more look at the code and I realized the save function was missing couple of checks. So replace meta_boxes.php:366 with this, if ( empty( $_POST['nonce_car_details'] ) ) { return; } check_admin_referer( 'save_car_details_meta', 'nonce_car_details' ); if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } if ( wp_is_post_autosave( $...


0

I ended up having to rework how I did things. Instead of saving the locations as meta data, I created a new custom post type for locations with each location having a lat/lng and the ID of the Event saved to it. So now I have the ability to query all the locations and build an array of Event IDs from that.


0

Here's an answer to question 1 that uses register_post_meta. It's also the start of an answer to question 2 by use of the prepare_callback option in show_in_rest . add_action( 'init', 'wpse_89033_register_custom_meta' ); function wpse_89033_register_custom_meta() { $post_types = [ 'post', 'page', 'attachment', ]; ...


0

I have run into the same problem and found even shorter solution (in terms of writing). if (isset($_POST['action']) && $_POST['action'] == 'editpost') { // do your update_post_meta, delete_post_meta, etc. } I tried to test it now on 5+ WP version and seems to fire only on editing or saving a new post.


0

One way of doing it would be to modify your current code and add the links in there: function category_name_shortcode() { global $post; $post_id = $post->ID; $catName = ""; foreach((get_the_category($post_id)) as $category){ $catName .= '<a href="' . get_term_link($category) . '">' . $category->name . '</a>, '; }...


0

If you want a HTML checkbox to be checked by default just add "checked" attribute: printf("<input type='checkbox' name='ins_street_address_shortcode' %s /> checked", $checkval);


1

Actually, your code is working, as long as $val == 'on'. Did you try debugging by doing echo $val ? If it's still not working, try hard refreshing (Ctrl + F5) your webpage, checkboxes tend to keep their state on normal refresh (F5). Also, please put your code directly on this forum, so the code is always accessible for future viewers ;)


1

You can't order by values inside serialised arrays in post meta. When you store an array like this: $value = [ [ 'plan_name' => 'name 1', 'plan_price' => '1', 'theType' => 'yesPaid', 'plan_space' => 'Unlimited', ], [ 'plan_name' => 'name 2', 'plan_price' =...


0

Keep in mind that if you leave this on the init action, this will occur on every page load. If you only want this to occur once or during another action, you'll need to change this. This will also timeout if you try to execute this on too many posts. function update_my_metadata() { $args = array( 'post_type' => 'post', // Only get ...


Top 50 recent answers are included