Add comment meta
Add comment meta
Add comment meta
There is no comment_ID until you are in the foreach loop. Try: $comments = get_comments($args); foreach($comments as $comment) : echo ‘<div id=”‘ . $comment->comment_ID . ‘”>Agent Name ‘ . $comment->comment_author . ‘Phone’ . $comment->comment_phone . ‘Reply’ . $comment->comment_content . ‘</div>’; echo get_comment_meta( $comment->comment_ID, ‘agents_condition’, true ); endforeach;
I assume you’re already properly using the WP Metadata API https://codex.wordpress.org/Metadata_API to attach the field to new comments and you just want to backfill for existing comments by stuffing the database? If it was my problem, I wouldn’t bother and would assume in my code that absence of meta implied no likes. If you use … Read more
I’ve found the source of the problem, I have redeclared the function comment_footer_die(). Which wordpress obviously can’t accept. My supplied code works as intended.
From a security point of view, it is always better not to have users you do not manually approve, as writing correct code that tests against a specific privilege is generally harder than a code that has a binary state of logged-in/not logged-in. Core has its privilege escalation bugs from time to time, but plugin … Read more
Use the get_avatar filter and develop a function to return whatever avatar you want.
The solution was to add a priority number to the comment_post action that was saving my rating value, as shown below: function save_comment_meta_data( $comment_id ) { if ( ( isset( $_POST[‘rating’] ) ) && ( $_POST[‘rating’] != ”) ) { $rating = wp_filter_nohtml_kses($_POST[‘rating’]); add_comment_meta( $comment_id, ‘rating’, $rating ); } } add_action( ‘comment_post’, ‘save_comment_meta_data’, 5 ); … Read more
You can use this function, which you’d add to the theme’s functions.php file, to update the average post rating which is saved in a private meta named _avg_rating (but you can of course rename it) — private meta has their name starting with an underscore (_): function update_post_avg_rating( $comment_id, $post_id = 0 ) { if … Read more
Don’t worry. I have found solution for your issue. you can use below code to display 5 top rated posts based on average rating. i have created below function to get top average rated post using sql queries and wp_query functions. here is updated function for all custom post type. function top_rated_post_via_comment_of_CPT($post_per_page = 5){ global … Read more
Your code uses this: number_format((float)$results[$i][‘avg_rate’], 2, ‘.’, ”) And if we look at where $i is set, we see this just before the loop: $i=0; and this: $i++; But I don’t see how this maps in any way to the current post when there’s a conditional, meaning that not everything in the results array is … Read more