How to update Post Meta values through the comment system
$parent_post is an object, update_post_meta requires the ID, so should be: update_post_meta( $parent_post->ID, ‘average_wr’, $commentdata );
$parent_post is an object, update_post_meta requires the ID, so should be: update_post_meta( $parent_post->ID, ‘average_wr’, $commentdata );
There may not be a need for a custom query, but I’d recommend it rather than hitting the database: – once for the WP_Query – once more for each post entry And then manually working out the math in PHP. Do it all at once with one MySQL statement. select sum(PM.meta_value) from wp_postmeta PM join … Read more
I assume you are trying to add metadata to the header, such as Open Graph. To do so, you can hook into wp_head and output your content there directly. Add this piece of code to your theme’s (or your child theme’s) functions.php file: //Hook to wp_head add_action(‘wp_head’,’add_my_metadata’); function add_my_metadata(){ // Echo any content your wish … Read more
get_post_meta takes 3 params, not two: get_post_meta( int $post_id, string $key = ”, bool $single = false ) As you can see, the third param is false by default. It means, that if you don’t pass it, the function will return an array with all custom fields for that key. If you have only one meta field with key prep_time, you’ll get: Array( … Read more
You shouldn’t change serialised PHP data structures directly. Serialised data contains the length of each value, and by changing a section of text, that length is no longer correct, and PHP runs into a fatal error and crashes. I don’t know what you are doing, but you should not modify serialised PHP strings manually.
This line is wrong: ‘meta_key’ => ‘adminscore’ + ‘user_like’ + ‘_count-views_all’ + ‘comment_count’, ‘meta_key’ only accepts string value. What you need is an additional meta key, e.g. “totalscore” that holds the total value of the scores you have for all the meta values. You can manually run a php function that calculates and store the … Read more
Okay as you added output of array. You can use the following to get the result. This will print the value of test meta key. <button><?php $my_meta = get_post_meta( $post->ID, ‘test’, true ); echo $my_meta[“test”]; ?></button> if your meta key is custom-name then you can get it like this. <?php $my_meta = get_post_meta( $post->ID, ‘custom-name’, … Read more
Your approach is good, you should run a basic check against the data tough. Otherwise you might get an array or a serialized object … which might lead to unexpected consequences (including security issues!) when you or someone else is trying to print the values. Maybe something like this is easier: $key = ‘_my_meta_key’; $value … Read more
update_field() is ACF function so I would guess the issue is with it. From quick look at source it calls get_field_object() and so on, so environment might not be sufficient for it to work correctly during import. There is no “half” state for native meta data, either it exists in database or it doesn’t. You … Read more
Just change, <?php if ( ‘post’ === get_post_type() ) codilight_meta_1();?> to <?php if ( ‘post’ === get_post_type() || ‘reviews’ === get_post_type()) codilight_meta_1();?>