How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?

Intercept the query on the posts_where filter. In there you can do a replacement of the non numeric values: preg_replace( “/[^0-9,.]/”, “”, $yourMeta ); Or in a (generic) code piece: add_action( ‘posts_where’, ‘wpse120784WhereDiameter’, 100 ); function wpse120784WhereDiameter( $where ) { // If conditions here – only target the cases where we need it # if … Read more

Creating a navigation menu of all posts of a custom post type and their children posts?

Here is the general logic that can be used to fetch the child custom posts What I’ve assumed here is, You create a county post, then you create a area post and from parent metabox you select the desired county post and save the post id in post_parent function wpse_128630_cp( $post_type=”county”, $post_parent=””, $posts_per_page = -1 … Read more

Remove category from query (show all posts in archive.php) pre_get_posts()

Just unsetting the cat variable probably isn’t enough. The pre_get_posts hook happens after the query variables have already been parsed. So there’s probably a tax_query with the taxonomy = category and the terms = your category. You’re already dumping the $query in your code, presumably for debugging. So, look at what you’re actually dumping. Do … Read more

Randomize Posts. Skip the first post in ascending order

I believe there are different ways of achieving this. Simplest way I could imagine is as below: $featured_content_query = new WP_Query( array( ‘post_type’ => ‘feature’, ‘offset’ => 1, ‘posts_per_page’ => 10, ‘order’ => ‘ASC’ ) ); shuffle( $featured_content_query ); //PHP function to randomise posts array You can then continue to use $featured_content_query as usual!

WP_Query returns random number of posts

There is no reason that query should behave differently on a single post page than on any other page. That is, there is no reason in the code posted. The only thing that I can think of would be that there is a filter interfering– perhaps a poorly written filter on pre_get_posts or post_limits. You … Read more