Sorting posts by meta values: 2 different orders

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

Show recent posts from excluded category

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

Using URL variables on a custom WP_Query

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

Custom pagination (Title, date and teaser)

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

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