Ordering Posts by parent category, name ascending
Ordering Posts by parent category, name ascending
Ordering Posts by parent category, name ascending
I think it should be able to hook into the posts_clauses filter to add a field to your sql query. add_filter( ‘posts_clauses’, ‘intercept_query_clauses’, 20, 1 ); function intercept_query_clauses( $pieces ){ global $wpdb; $pieces[‘fields’].=’, (IF(UNIX_TIMESTAMP()>=’.$wpdb->postmeta.’.meta_value,’.$wpdb->postmeta.’.meta_value,(UNIX-TIMESTAMP() – ‘.$wpdb->postmeta.’.meta_value)+UNIX_TIMESTAMP(‘2099-01-01′))) as timestamp_direction’; $pieces[‘orderby’]=’timestamp_direction ASC’; return $pieces; } The logic is as follows: Let’s say you have some timestamps in … Read more
Website goes slow down after importing long database
Pieter Goosen solved the issue with with this suggestion. if ( $query->is_home() || $query->is_archive() ) Should be: if (!is_admin() && $query->is_main_query() && ( $query->is_home() || $query->is_archive() ) ) Then explains why this solution worked: is_main_query() only returns true in the main query. pre_get_posts alters all queries back end and front end, there is no designation … Read more
WordPress doesn’t handle this logic qutomatically so you will have do do it manually. What you need to do is: Read the url parameter with get_query_var( ‘category_name’ ); injects it in your custom WP_Query: $custom_query_args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => … Read more
My query was wrong. Should be using ‘meta_value’ instead of ‘meta_value_num’ since my ‘sort_name’ is text based, not numeric. Big thanks to John Huebner on the ACF message board for answering this one.
Multiple tax_queries: display posts titles from several custom taxonomie
WP_Query using meta_query with LIKE doesn’t return what it should
I assume you’re talking about single posts, not archives – get_next_posts_link gets the next archive page, get_next_post_link gets the post next to the current one (note the plural difference). If so, the next/previous post link functions are just wrappers for get_adjacent_post(): <?php if ( $the_query->max_num_pages > 1 ) : ?> <nav class=”prev-next-posts”> <?php if ( … Read more
After doing a bit more research I was able to figure out a way to do this, though it seems like it probably isn’t a great solution because it takes way way too long to run as it basically just loops through every post using get_post_gallery(). Perhaps there is a better way though – maybe … Read more