keesiemeijer on "wp_query query with two custom posts shows all post instead of matching ID"

ساخت وبلاگ

I have two types of custom posts - a "neighborhood" and an "area". Either of these can belong to a "base". When I am querying just the "neighborhoods", the base page has no issue pulling up the right ones, but if I add in "areas", it just pulls in all the areas instead of the one associated with the base id. Can anyone tell me what I am doing wrong?

For reference:
Area -> can have Neighborhoods
Base -> can have Area + Neighborhoods

Neighborhood Grid Shortcode:

function hoodGrid() { global $post; $thisBaseID = $post->ID; $grid_markup = ''; $hood_query = new WP_Query( array( 'post_type' => array ('neighborhoods','areas'), 'post__in' => get_option('sticky_posts'), 'orderby' => 'title', 'order' => 'ASC', 'meta_key' => 'hood_near_base', 'meta_value' => $thisBaseID, 'posts_per_page' => -1 ) ); $grid_markup .= '<div class="iso-grid row">'; if ($hood_query->have_posts()) : while ($hood_query->have_posts()) : $hood_query->the_post(); $hood_cover_name = rwmb_meta( 'hood_cover_name' ); $hood_cover_img = array_shift(rwmb_meta( 'hood_cover_img' ) )['full_url']; if(rwmb_meta( 'hood_cover_tint' )) { $hood_cover_tint = rwmb_meta( 'hood_cover_tint' ); } else { $hood_cover_tint = ''; } if(rwmb_meta( 'hood_cover_height' )) { $hood_cover_height = rwmb_meta( 'hood_cover_height' ); } else { $hood_cover_height = 'short'; } if(rwmb_meta( 'hood_cover_width' ) == 'one_third') { $hood_cover_width = 'col-xs-6 col-sm-4'; } elseif(rwmb_meta( 'hood_cover_width' ) == 'two_thirds') { $hood_cover_width = 'col-xs-6 col-sm-8'; } $grid_markup .= '<a href="'. get_permalink() .'" class="grid-item '. $hood_cover_height .' '. $hood_cover_width .'">'; $grid_markup .= '<div class="img-wrapper"><div class="img-bg" style="background-image: url('. $hood_cover_img .');"> </div></div>'; $grid_markup .= '<div class="img-overlay '. $hood_cover_tint .'">'; $grid_markup .= '<div class="img-title">'. $hood_cover_name .'</div>'; $grid_markup .= '</div>'; $grid_markup .= '</a>'; endwhile; endif; wp_reset_query(); $grid_markup .= '</div>'; // END .iso-grid retu $grid_markup;
}
add_shortcode('heighborhoods_grid', 'hoodGrid');

Here is the Metabox used to input the information of the neighborhood grid:

add_filter( 'rwmb_meta_boxes', 'hood_cmbs' );
function hood_cmbs( $meta_boxes ) { $meta_boxes[] = array( 'post_types' => 'neighborhoods', 'title' => __( 'Neighborhood cover (used in grid on base template)', '' ), 'fields' => array( array( 'id' => 'hood_cover_name', 'name' => __( 'Neighborhood name', '' ), 'type' => 'text', ), array( 'id' => 'hood_cover_img', 'name' => __( 'Cover image', '' ), 'type' => 'image_advanced', ), array( 'id' => 'hood_cover_height', 'name' => __( 'Cover height', '' ), 'type' => 'select', 'options' => array( 'short' => __( 'Short', '' ), 'tall' => __( 'Tall', '' ), ), 'std' => 'short', ), array( 'id' => 'hood_cover_width', 'name' => __( 'Cover width', '' ), 'type' => 'select', 'options' => array( 'one_third' => __( '1/3rd the container', '' ), 'two_thirds' => __( '2/3rds the container', '' ), ), 'std' => 'one_third', ), array( 'id' => 'hood_cover_tint', 'name' => __( 'Cover tint color', '' ), 'type' => 'select', 'options' => array( 'blue' => __( 'Blue', '' ), 'green' => __( 'Green', '' ), 'red' => __( 'Red', '' ), 'teal' => __( 'Teal', '' ), 'yellow' => __( 'Yellow', '' ), ), ), array( 'id' => 'hood_near_base', 'name' => __( 'Near base', '' ), 'multiple' => true, 'type' => 'select_advanced', 'options' => get_cpt_options( array( 'post_type' => array('bases', 'areas')) ), ), ), ); retu $meta_boxes;
}

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 238 تاريخ : چهارشنبه 16 تير 1395 ساعت: 19:42