Orderby if between two meta fields
Orderby if between two meta fields
Orderby if between two meta fields
As I already pointed in the comment, all you need to do is change your orderby parameter so that the meta_prio is the first item and followed by the meta_start. So your orderby should look like: // This array forms an ORDER BY clause with each array item being a column that // MySQL use … Read more
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
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
How can I create a meta_query with an array of dates?
I’ve found the solution (I suppose): looks like that the right operator in this case is “NOT EXISTS”. I’ve noticed that in the db postmeta table I’ve got only the records of the “is_hidden” key with value “on”…
You’d have to look more closely at how the old theme displays the postmeta. At this point, you have a few options: Create a child theme for your new theme, and in its PHP file to display single posts, set the child theme up to display the postmeta just like your old theme did. (You … Read more
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.
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
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; ?>