Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 1. This flushes the WordPress cache
- * @see https://developer.wordpress.org/reference/functions/wp_cache_flush/
- */
- add_action('init', function () {
- wp_cache_flush();
- });
- /**
- * 2. Finally, here we manually query the first 10 reviews, review posts, and rating IDs
- * in order to confirm that the reviews are being queried correctly
- */
- add_action('wp_footer', function () {
- global $wpdb;
- // get the 10 most recent (post <-> rating) IDs
- $reviewIds = $wpdb->get_col("
- SELECT r.review_id
- FROM {$wpdb->prefix}glsr_ratings AS r
- INNER JOIN {$wpdb->posts} AS p ON r.review_id = p.ID
- WHERE 1=1 AND r.is_approved = 1 AND r.type = 'local'
- GROUP BY r.review_id
- ORDER BY r.is_pinned desc, p.post_date desc
- LIMIT 10
- ");
- // get the 10 most recent reviews from the ratings table
- $ratings = $wpdb->get_results("
- SELECT r.*
- FROM {$wpdb->prefix}glsr_ratings AS r
- LIMIT 10
- ");
- // get the 10 most recent reviews from the posts table
- $posts = $wpdb->get_results("
- SELECT
- ID,
- post_author,
- post_date,
- post_date_gmt,
- post_name,
- post_title,
- post_status,
- post_modified,
- post_modified_gmt,
- menu_order
- FROM {$wpdb->posts}
- WHERE post_type = 'site-review'
- AND post_status IN ('publish', 'pending')
- ORDER BY post_date
- LIMIT 10
- ");
- // Get the meta data of the first 10 review posts
- $meta = [];
- foreach ($posts as $post) {
- $meta[$post->ID] = get_post_meta($post->ID);
- }
- // finally, log results to the console
- glsr_log([
- 'review_ids' => $reviewIds,
- 'ratings' => $ratings,
- 'posts' => $posts,
- 'meta' => $meta,
- ]);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement