Limit connection to one post?
-
Two questions really:
1) Can the connection be setup to limit the connection to a single post?2) Is there an efficient way to query a singular connected post and return it rather than a full $query.
FWIW, I’m connecting a CPT to a post and pages to be used as a featured/hero image.
Currently I’m using this, but thinking there might be a better way:
<?php function jb_feature_area() { // Find connected pages $connected = new WP_Query( array( 'connected_type' => 'posts_to_whitepaper', 'connected_items' => get_queried_object(), 'nopaging' => true, ) ); // Display connected pages if ( $connected->have_posts() ) { # while ( $connected->have_posts() ) : $connected->the_post(); $connected->the_post(); $post_thumbnail_id = get_post_thumbnail_id(); $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id ); echo '<div id="page-feature" class="page-feature" style="background-image: url(' . $post_thumbnail_url . ')">'; echo '<div class="feature-excerpt-wrap">'; echo '<h2>' . get_the_title() . '</h2>'; echo '<p>' . get_the_excerpt() . '</p>'; echo '</div> <!-- end .feature-excerpt-wrap -->'; echo '</div> <!-- end .home-feature -->'; # endwhile; } // Prevent weirdness wp_reset_postdata(); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Limit connection to one post?’ is closed to new replies.