Loop through Custom Post Type, and then show children within each iteration

Placing the following code within the WP_Query loop works: <?php $parent_page_id = ( ‘0’ != $post->post_parent ? $post->post_parent : $post->ID ); $mypages = get_pages( array( ‘child_of’ => $parent_page_id, ‘post_type’ => ‘programs’ ) ); foreach( $mypages as $page ) { $content = $page->post_content; if ( ! $content ) // Check for empty page continue; $content = … Read more

Custom Search Result Page displaying only 1 result.

Change <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> to <?php if ($allsearch->have_posts()) : ?> <?php while ($allsearch->have_posts()) : $allsearch->the_post(); ?> because otherwise you don’t utilize your custom query. See WP_Query Usage. Also call wp_reset_query(); after the Loop. See wp_reset_query Description. Actually, you don’t need wp_reset_query(); because you use custom WP_Query object … Read more

How to find what index page a post is on?

There’s no way to do it directly but there’s a way to determine the position of a particular row in a mysql query. You can find out how to do it here- https://stackoverflow.com/questions/3614666/mysql-get-row-position-in-order-by Once you have the position you can divide it with the value from get_option(‘posts_per_page’) to determine the correct page number.

Query “Category A” + 1 post from “Category B” – how?

I don’t see a way to do this with WP_Query alone. However… function posts_where_add_post_wpse_96030($where) { global $wpdb; return $where.” OR {$wpdb->posts}.ID = 1″; } add_filter(‘posts_where’,’posts_where_add_post_wpse_96030′); $query = new WP_Query( ‘cat=9’ ); That will alter the query everywhere it runs so you will need to add conditions to the callback so that $where is only altered … Read more

WP_Query returns more results than expected

There is no post_title in WP_Query‘s parameter list. You need to use name, which accepts a slug not the actual post title. name (string) – use post slug. It looks like all you are doing is getting an ID. That is a very heavy query if that is all you need. You can alter the … Read more

Multiple relationships in a query

Unfortunately, meta queries do not support a combination of AND & OR. But what you can do, is make two queries, one for each rule, then combine the results. $group_1 = get_posts( array( ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘meta_query’ => array ( array ( ‘key’ => ‘field1’, ‘value’ => ‘data1’, ), array ( ‘key’ … Read more