WP_Query, pre_get_posts and offset

It helps to write problems down. After I haven’t used pre_get_posts extensively, I focused too much on that area for the cause, but it was the if clause. Changed to if ( ! is_admin() && $query->is_main_query() && ! is_post_type_archive( ‘cpt’ ) ) { return $query; } elseif ( ! is_admin() && $query->is_main_query() && is_post_type_archive( ‘cpt’ … Read more

wp_query check if integer exists in custom field’s array

First of all, your meta_query is wrong. It should be an array of an array, not just an array So, the following ‘meta_query’ => array ( ‘key’ => ‘qd_resource_author_selector’, ‘value’ => $myAuthor, ), becomes ‘meta_query’ => array ( array( ‘key’ => ‘qd_resource_author_selector’, ‘value’ => $myAuthor, ), ), Secondly, you can optimize your query. You are … Read more

Wp redirect to url with ampersand string

Nothing I see in Core would do that in either wp_redirect() or wp_sanitize_redirect() (which is used by wp_redirect()). However… both functions are pluggable and so could have been replaced by theme or plugin code. And wp_redirect() has the wp_redirect filter that can be used to alter the redirect location– the part you are having trouble … Read more

Not getting metavalue

The mysql_*() functions won’t work after WP 3.9, so don’t use them. See Make WordPress Core entry MySQL in WordPress 3.9. It is adviced to use $wpdb methods instead – if necessary. In your case – as far as I can tell – it isn’t necessary at all. You can use the relevant API functions … Read more

WP_Query custom query showing only 10 posts on all pages

One of two things is happening that I can think of: You have sticky posts showing up. Try adding an ignore_stickie_posts argument. $args = array ( ‘pagination’ => true, ‘posts_per_page’ => 5, ‘ignore_stickie_posts’ => true, ); See: https://wordpress.stackexchange.com/a/85658/21376 You have a poorly written (too global) pre_get_posts filter. Something like: function naughty_pre_get_posts( $query ) { $query->set( … Read more