Correct processing of `$_POST`, following WordPress Coding Standards
Correct processing of `$_POST`, following WordPress Coding Standards
Correct processing of `$_POST`, following WordPress Coding Standards
Lets break this down, Advanced Custom Fields (ACF) does save the data as custom field/post meta, I guess it seems all to obvious, but it is better to confirm it, and ElasticPress does set up custom fields automatically to include them into the search index. ElasticPress does this unless the meta data is hidden, which … Read more
If you want both posts that have and do not have a meta key, you need an OR relation meta query to select both posts with key and those where it does not exist. $args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_post_like_count’, ‘compare’ => ‘EXISTS’ ), array( ‘key’ => ‘_post_like_count’, … Read more
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 … Read more
Apparently the serialized data got corrupt, calling the field by query got me this error. WordPress does not return an error when the serialized data is corrupt just a bool(false). Solved this by insert/update the serialized data in a base64_encode() and call it with base64_decode(). This seems to do the trick and data can be … Read more
$querystr = ” SELECT DISTINCT — post_meta.meta_value, key2.name as tag_name,key2.slug as tag_slug FROM $wpdb->posts key1 LEFT JOIN $wpdb->term_relationships ON (key1.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->postmeta post_meta ON (key1.ID = post_meta.post_id) LEFT JOIN $wpdb->terms key2 ON ($wpdb->term_relationships.term_taxonomy_id = key2.term_id) LEFT JOIN $wpdb->term_taxonomy key3 ON ($wpdb->term_relationships.term_taxonomy_id = key3.term_id) WHERE 1=1 AND post_meta.meta_key = ‘likes_count’ AND post_meta.meta_value > … Read more
A little late, but I just had this issue where adding a taxonomy term was working, but adding post meta wasn’t. The solution was to set a higher priority. The default priority is 10, so try for instance priority of 100: add_action( ‘save_post_dealer’, ‘save_dealer_long_lat’, 100, 1);
OK, so you have some code that uses add_post_meta and you want to make it add only unique values. The problem in here is that add_post_meta does exactly what it’s name is saying – it adds a post meta value. There is 4th arg for that function that’s called unique, but it work based on … Read more
Running the wp media regenerate command from WP-CLI with the –only-missing argument is quite fast (takes about 30 seconds for 4000 images) and rebuilds _wp_attachment_metadata correctly: wp media regenerate –only-missing
You can get using this using SQL global $wpdb; // For single record $wpdb->get_row(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2”); // For multiple records $wpdb->get_results(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key = $param1 AND meta_value = $param2” ); Use this for query $args = array( ‘posts_per_page’ => 10, // -1 for … Read more