V
V
Vladimir Kulikov2020-06-27 11:40:25
WordPress
Vladimir Kulikov, 2020-06-27 11:40:25

How to display entries from the beginning to the new ones and add random ones with a low rating?

Hello.
In the records there is such a parameter "Rating".
Entries with a rating between 10 and 100 should be displayed in order, from highest to lowest.
And those that are less than or equal to 10 should randomly appear among those that are displayed in order.
How to implement this?

I display records, records with a rating of more than 10, I was able to display. And how to throw random ones with a low rating to them. Don't know(

$query = new WP_Query( array(
                        'post_type' => 'models', 
                        'posts_per_page' => -1,
                        'meta_query' => array(
                          'reiting_query' => array(
                              'key'     => 'reiting',
                              'value'   => 10,
                              'type' => 'NUMERIC',
                              'compare' => '>',
                          ),
                        ),
                        'orderby' => 'reiting_query',
     ) );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yarovikov, 2020-06-27
@it_proger29

Based on complexity

should randomly appear among those that are displayed in order

There is a suspicion that it does not.
You can combine two arrays of posts (high order and low random order) somewhere like this:
$args1 = array(
  // тут параметры первого массива
  'post__in' => $ids,
);

$args2 = array(
  // тут параметры второго массива с низким рейтингом
  'orderby' => 'rand',
  'post__in' => $ids,
);

$args1 = get_posts( $args1 );
$args2 = get_posts( $args2 );
$merged_ids = array_merge( $args1, $args2 );

$args_final = array(
  // тут параметры общего массива
  'post__in' => $merged_ids,
  'orderby' => 'post__in',
);	

$query = new WP_Query( args_final );

But accidentally throwing posts from the second into the array of the first is a very non-trivial task, or I have not woken up yet.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question