WP_Query with LIKE in meta gives strange query

No, you’re doing everything right and this should actually work as those placeholders are removed at a later point before actually executing the query. This is part of a security measure introduced with WordPress 4.8.3. Quoting from the corresponding developer note: As part of the WordPress 4.8.3 release, there is a change in esc_sql() behaviour … Read more

Query certain amount of posts from multiple dates

You’re just about there. Each date_query array represents a separate condition to filter by. By default, these are combined using AND which limits the scope further. In your case, you want to change the relation to OR and then add the different years as their own separate conditions in the array. $args = array( ‘date_query’ … Read more

Order by two meta keys

I’m not 100% certain what specific order you’re asking for, but you just need to assign an associative array to the ‘orderby’ value. Here’s an example: $args = array( ‘post_type’ => ‘brands’, ‘meta_query’ => array( array( ‘key’ => ‘br_type’, ‘value’ => ‘Aviation’ ), array( ‘key’ => ‘br_category’ ), array( ‘key’ => ‘br_name’ ) ), ‘posts_per_page’ … Read more

querying with custom meta field with meta_query

There’s actually a better solution that will (hopefully) be rolling out in WordPress 3.4 — you can run the patch as a hotfix now if you’d like, but here’s the TRAC link for the patch: http://core.trac.wordpress.org/ticket/18158 With this, you can do … $my_query = new WP_Query( array( ‘meta_query’ => array( array( ‘key’ => ‘foo’, ‘compare’ … Read more

wp_query order by title

If you’re trying to get them to order by ascending price, the problem is that ordering by title is a string comparison, not numeric. A solution would be to put the price in a custom field and orderby your custom field rather than title. You would add a meta_key param with the name of your … Read more

get_posts not finding argument: post_name

Aha, despite there being a postmeta field of post_name->’slug’, the correct syntax (which mirrors that of WP_Query, is $args = array( ‘name’ => $postSlug, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $slugPosts = get_posts($args); Where ‘name’ is the key in the query (for posts, ‘postname’ for page). Doesn’t make much sense but might as well … Read more

How to Access Global $multipage or Global $numpages outside the loop?

Just inspect the current post content for ‘<!–nextpage–>’: function wpse_check_multi_page() { $num_pages = substr_count( $GLOBALS[‘post’]->post_content, ‘<!–nextpage–>’ ) + 1; $current_page = get_query_var( ‘page’ ); return array ( $num_pages, $current_page ); } On page 2 of 3 that returns: Array ( [0] => 3 [1] => 2 ) On an unpaged post it returns: Array ( … Read more

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