Answer the question
In order to leave comments, you need to log in
Sorting Wordpress posts?
Good day!
The question is, I would like to sort posts by rating (there is a plugin WP-PostRatings)
There are fields for entering values from-to by rating.
But if in the loop I start to check the condition of the op rating, then the while (have_posts ()) loop is not downloaded, in yoga it says that the script has been running for more than 30 seconds. tell me what's wrong??
require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php');
global $wpdb;
global $wp_query, $post;
/* Sort by time */
if (isset($_POST['submit_range'])) {
$time_from = htmlspecialchars($_POST['amount1']);
$time_to = htmlspecialchars($_POST['amount2']);
$rate_from = htmlspecialchars($_POST['rate_from']);
$rate_to = htmlspecialchars($_POST['rate_to']);
}
$tables = $wpdb->get_results("SELECT `rating_postid`, `rating_rating` FROM `wp_ratings` ");
foreach ($tables as $table) {
$p_id[] = $table->rating_postid;
$rate[] = $table->rating_rating;
}
$i = 0;
$custom_query = new WP_Query( 'cat='.$cat );
if($custom_query->have_posts()) :
/* Start the Loop */
while ( $custom_query->have_posts() ) :
if (($rate[$i] <= $rate_to) && ($rate[$i] >= $rate_from)) {
$custom_query->the_post();
get_template_part('template-parts/content', get_post_type());
}
endwhile;
endif;
// Reset Post Data
wp_reset_postdata();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question