Sort by meta key on archive page

Use pre_get_posts to alter the main query before it is run. The action runs on every query, use the Conditional Tags to target specific queries. function wpd_sort_by_meta( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘meta_key’, ‘your_meta_key’ ); $query->set( ‘orderby’, ‘meta_value_num’ ); } } add_action( ‘pre_get_posts’, ‘wpd_sort_by_meta’ );

view queries made?

See this codex page. in wp-config.php: define(‘SAVEQUERIES’, true); then in your template: if (current_user_can(‘administrator’)){ global $wpdb; echo “<pre>”; print_r($wpdb->queries); echo “</pre>”; } or without the above SAVEQUERIES, you can still see just the main query: global $wp_query; echo $wp_query->request; or to see all of $wp_query: <pre> <?php print_r($wp_query); ?> </pre>

WP Query and order by particular specified IDs

To keep the same post order as it was passed to the post__in parameter, you need to pass post__in as value to orderby argument and ASC to the order argument $query_args = [ ‘posts_per_page’ => $products, ‘no_found_rows’ => true, ‘post_type’ => ‘product’, ‘post__in’ => [161,165,131,202], ‘orderby’ => ‘post__in’, ‘order’ => ‘ASC’ ]; EDIT Looking at … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)