K
K
killerben2021-09-09 18:42:31
WordPress
killerben, 2021-09-09 18:42:31

Wordpress: how to make "on approval" entries always on top?

Tell me how you can do so that the records that are under approval are always higher than the rest of the records.
I dug into the code for half a day, but I couldn’t do it, plugins also don’t seem to fit my problem.

71VRd3PD.jpg?download=1&name=%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2009-09-2021%2018:40 :11.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-09-10
@killerben

All post requests can be edited on the hook pre_get_posts. For admin requests, it looks something like this:

add_action( 'pre_get_posts', 'admin_pre_get_posts', 1 );
function admin_pre_get_posts( $query ) {

  if( is_admin() ) {
    $query->set( 'posts_per_page', 200 );
  }

}

The orderby argument is responsible for sorting posts , but, unfortunately, sorting by the post_status field cannot be done right away.
You can:
  1. Try solutions from the internet
  2. Add your field to post_meta on the hook save_postand sort by this field
  3. Score, because you even have a separate tab "Pending approval" on the screenshot, use it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question