complex get_posts() query to select child pages

You need a loop for this to handle the condition: /** list for course and childless department pages */ $course_and_childless_department_pages = array(); /** get department pages */ $department_pages = get_children( array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ) ); foreach ( $department_pages as $department_page ) { /** get course pages (for department … Read more

Reset postdata not working on WP_Query in functions.php

You don’t need to modify the global current post, just use the get_posts() function instead of WP_Query(). function get_root_project_value( $meta_key ) { if ( empty( $meta_key ) ){ return false; } $args = array( ‘post_type’ => ‘slug’, ‘meta_query’ => array( array( ‘key’ => ‘project_is_root_project’, ‘value’ => ‘1’, ), ), ‘posts_per_page’ => 1, // If you … Read more

Custom post type loop with custom category filtering

Is that category or custom taxonomy? if this is a category, then try this one. <?php $loop = new WP_Query( array( ‘post_type’ => ‘portfolio’, ‘posts_per_page’ => 50, ‘category__in’ => array(‘8′,’9′,’10’), // your category ids ) ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class=”half-column”> <h2><?php the_title(); ?></h2> </div> <?php endwhile; wp_reset_postdata(); ?> Or if … Read more