Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `
- <?php
- /**
- * Plugin Name: Display Posts to Posts
- // Create the shortcode
- add_shortcode(‘p2p’, ‘display_post2post’);
- function display_post2post($atts) {
- extract( shortcode_atts( array(
- ‘relation_post’ => ”, //posts_to_pages or relationship targeted
- // other attributes to pass?
- ), $atts ) );
- $args = array(
- ‘relation_post’ => $connected_type,
- ‘connected_type’ => $connected_type,
- ‘connected_items’ => get_queried_object_id(),
- ‘nopaging’ => true,
- // other filters ?
- );
- $return = ";
- $connected = new WP_Query($args);
- if ( $connected->have_posts() ):
- $return .= "<h3>Related posts:</h3>;
- $return .= "
- <ul>";
- while ( $connected->have_posts() ): $connected->the_post();
- $return .= "
- <li><a>"><?php the_title(); ?></a></li>
- ";
- endwhile;
- $return .= "</ul>
- ";
- // Prevent weirdness
- wp_reset_postdata();
- $return .= ”;
- endif; wp_reset_query();
- if (!empty($return)) return $return;
- }
- ?>
- `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement