yaffar
Forum Replies Created
-
Forum: Hacks
In reply to: Get meta of custom post type for WP REST APII’m trying to work around it using the update_post_meta() to create and fill automatically a new custom meta, but currently I’m struggling on how to make the call to update all of the posts on a single query (There are more than 30k). I’ll let you know how it goes ??
Forum: Hacks
In reply to: Get meta of custom post type for WP REST APIThank you so much for your help bcworkz that worked out great, I’m almost done with my custom routes, but I need just one more thing and I’m hoping you could find me solve it. Now I need to order my query by the highest count of reviews but this is not a meta value of my post it is inside the database, I did the following to get the value and send it to the route.
` /* Get place rating average and amount of rates*/
$rating_table_name = Extras\tg_get_rating_table_name();
$avg_rating = $wpdb->get_var(
$wpdb->prepare(
“select COALESCE(avg(rating_rating),0) from $rating_table_name where rating_rating > 0 and rating_postid in (%d)”,$post->ID));
$rating_count = $wpdb->get_var(
$wpdb->prepare(
“select COUNT(rating_id) from $rating_table_name where rating_rating > 0 and rating_postid in (%d)”,$post->ID));/*Get Featured image*/
$thumbnail_id = get_post_thumbnail_id($post);
if ($thumbnail_id) {
$thumbnail = array();
$thumbnail[$image_size] = wp_get_attachment_image_src($thumbnail_id, $image_size);
}// Get the permalink for the blog*/
$post->link = get_permalink($post->ID);/* Custom meta for custom routes*/
$post->Mapa = get_post_meta($post->ID, ‘map’);
$post->Usuario = $user;
$post->Favorita = $favorite;
$post->Bookmark = $bookmarked;
$post->Rating = $avg_rating;
$post->Votos = $rating_count;`and I’m trying something similar to make it work in the query but it isn’t. Can you help me figure it out?
This is what I’m doing right now
$rating_table_name = Extras\tg_get_rating_table_name(); $rating_count = $wpdb->get_var( $wpdb->prepare( "select COUNT(rating_id) from $rating_table_name where rating_rating > 0 and rating_postid in (%d)",$post->ID)); $query = new WP_Query( array( 'post_type' => array('post', 'place'), //'paged' => (isset($_GET['paged'])) ? $_GET['paged'] : 1, 'posts_per_page' => 3, 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_key' => $rating_count, ) );