Better way to display posts from specific categories, in a grid layout

I think the general suggestion is to use WP_Query instead of query_posts partly because query_posts used WP_query in a simplified way and can cause problems down the road. So for sure check out the WP_Query page, specifically the Multiple Loops example: http://codex.wordpress.org/Class_Reference/WP_Query#Multiple_Loops So the code using WP_Query would look something like this: <?php $counter = … Read more

Query posts by specific word on title

The answer to this question is here. The full credit of the answer to my question goes for the author of the answer birgire. All I had to do was slightly change is plugin “Support for post name like in WP_Query” turning it into a function like this: add_filter( ‘posts_where’, ‘title_like_posts_where’, 10, 2 ); function … Read more

Sort by custom field is not working

Piter is right, don’t use query_posts. You could do something like: $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; $args = array( ‘post_type’ => ‘properties’, ‘meta_key’ => ‘pd_city’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘posts_per_page’ => 5, ‘paged’ => $paged ); $query = new WP_Query( $args ); Just make sure you have the values … Read more

posts_per_page override by default settings

Regarding my comment to Steve’s answer, see also Override the default number of posts to show for a single loop? The “method” version of Steve’s answer would be: function limit_posts_per_archive_page( $query ) { if ( $query->is_post_type_archive( ‘zitate-sprueche’ ) || $query->is_tax(‘zitate-kats’) || $query->is_post_type_archive(‘daten’) || $query->is_tax(‘daten-kats’)) { $limit = 27; } else $limit = get_option(‘posts_per_page’); } $query->set( … Read more

Query with custom taxonomy not working

The solution is to use: ‘taxonomy’ => ‘meal’, ‘field’ => ‘slug’, ‘terms’ => ‘breakfast’ The taxonomy and terms are obvious, but why does field have to be slug? When you add taxonomy parameters, you can specify what ‘breakfast’ is– via the field. It could be the term’s ID, the full name, or slug. See the … Read more

Pagination is not working on single-{slug}.php but works fine on page-{slug}.php

You forgot to start a new query. And if you dont use have post on your custom query, you will get the main current query, in your case is your single. $args = array( ‘post_type’ => ‘crew’, ‘posts_per_page’ => 10 ); $your_custom_query = new WP_Query( $args ); // is that you forgot // The Loop … Read more

Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first

First of all, just to clarify, in a normal situation without the specific order requirements, and assuming you are doing this on pre_get_posts hook, you would just do as follows: add_action(‘pre_get_posts’, function ($query) { // only perform for a given query // do your checks and return early if (! $query->is_main_query() || ! $query->is_home()) { … Read more

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