Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In functions.php:
- <?php
- add_action('init', 'dgo_connection_types', 100);
- add_filter('p2p_connectable_args', 'dgo_connectable_places', 10, 2);
- function dgo_connectable_places($args, $context) {
- if ('place' == $args['post_type']) {
- global $wpdb;
- $query = "SELECT $wpdb->p2p.p2p_to AS post_id FROM $wpdb->p2p";
- $result = $wpdb->get_col($query);
- $args['post__not_in'] = $result;
- $args['orderby'] = 'date';
- $args['order'] = 'ASC';
- }
- return $args;
- }
- function dgo_connection_types() {
- if (!function_exists('p2p_register_connection_type'))
- return;
- global $postplaces;
- $postplaces = p2p_register_connection_type(array(
- 'from' => 'post',
- 'to' => 'place'
- ));
- }
- ?>
- In index.php:
- <?php if (have_posts()) : ?>
- <?php
- global $wp_query;
- $postplaces->each_connected($wp_query);
- ?>
- <?php while (have_posts()) : the_post(); ?>
- <?php global $post; ?>
- <?php print_r($post); // $post->connected is not present ?>
- <?php endwhile; ?>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement