WordPress Query custom ordering by temporary variable

Update: The User has clarified the request in the comment to my answer, so i add some info above my original answer. The original answer is still valid 😉 To use external data for your “main” query, you can use the pre_get_posts hook. Use it like this: add_action(‘pre_get_posts’,’get_radius_instructors_for_my_posts’); function get_radius_instructors_for_my_posts($query){ if($query->is_main_query() && !is_admin()){ if($query->is_search()){ //use … Read more

meta_query Where the key value is stored as an array

Thanks to the help of @JacobPeattie the problem was how the data was being saved. So instead of: if(isset($_POST[‘assign-classes’])) { update_post_meta( $post->ID, ‘assign-classes’, $_POST[‘assign-classes’] ); } It is now: delete_post_meta($post->ID, “assign-classes”); for($i = 0; $i < count($_POST[‘assign-classes-all’]); $i++){ add_post_meta( $post->ID, ‘assign-classes’, $_POST[‘assign-classes-all’][$i], false ); } Only thing that was weird is that at first I … Read more

Custom query result empty on page 2

It’s a custom dynamic page, used only for this specific query result. The problem was form action=”” being empty. $_GET parameters were sent to the same page i.e. /result-page/?filter-options=800 which is fine but while on page-2, the results were sent to /result-page/page/2/?filter-options=800. Setting the form action=”/result-page” solved the problem. Thanks.

WordPress query: merge meta key (number) values and sort

I think this is the syntax you are after: $args = [ ‘posts_per_page’ => 5, ‘post_type’ => ‘post’, ‘meta_query’ => [ ‘relation’ => ‘OR’, ‘rating_au_clause’ => [ ‘key’ => ‘rating_au’, ‘compare’ => ‘EXISTS’ ], ‘rating_overall_clause’ => [ ‘key’ => ‘rating_overall’, ‘compare’ => ‘EXISTS’ ] ], ‘orderby’ => [ ‘rating_au_clause’ => ‘ASC’, ‘rating_overall_clause’ => ‘DESC’, ], … Read more

Query for current post

You shouldn’t be writing any query. WordPress does this for you. You single-{post type}.php template should only contain the standard loop: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); // Display post content endwhile; endif; ?>

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