/**
 * Retrieve a post's relations as a list with specified format.
 *
 * @param int $id Post ID.
 * @param string|array $post_type Post type name.
 * @param string $before Optional. Before list.
 * @param string $sep Optional. Separate items using this.
 * @param string $after Optional. After list.
 * @return string
 */
function get_the_relations($id = 0, $post_type, $before = '', $sep = '', $after = '')
{
    $relations = rpt_get_object_relation($id, $post_type, false);
    if (is_wp_error($relations)) {
        return $relations;
    }
    if (empty($relations)) {
        return false;
    }
    foreach ($relations as $relation) {
        $link = get_permalink($relation);
        if (is_wp_error($link)) {
            return $link;
        }
        $relation_links[] = '<a href="' . $link . '" title="' . esc_attr(get_the_title($relation)) . '">' . get_the_title($relation) . '</a>';
    }
    $relation_links = apply_filters("get_the_relations", $relation_links, $post_type);
    return $before . join($sep, $relation_links) . $after;
}
 /**
  * Client side widget render
  *
  * @param array $args
  * @param array $instance
  * @return void
  * @author Amaury Balmer
  */
 public function widget($args, $instance)
 {
     global $wp_query;
     extract($args);
     // Singular view ?
     if (!is_singular()) {
         return false;
     }
     // Post type egal "ALL", delete it !
     if ($instance['post_type'] == 'all') {
         $instance['post_type'] = array();
     }
     // Related IDs for this view ?
     $ids = rpt_get_object_relation($wp_query->get_queried_object_id(), $instance['post_type']);
     if ($ids == false || empty($ids)) {
         return false;
     }
     // Build or not the name of the widget
     if (!empty($instance['title'])) {
         $title = $instance['title'];
     } else {
         $custom_type = get_post_type_object($instance['post_type']);
         $title = $custom_type->labels->name;
     }
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $items_query = new WP_Query(array('post__in' => $ids, 'post_type' => $instance['post_type'], 'post_status' => 'publish', 'showposts' => $instance['number'], 'orderby' => $instance['orderby'], 'order' => $instance['order']));
     echo $before_widget;
     // Display the widget, allow take template from child or parent theme
     if (is_file(STYLESHEETPATH . '/widget-views/rpt-widget.php')) {
         // Use custom template from child theme
         include STYLESHEETPATH . '/widget-views/rpt-widget.php';
     } elseif (is_file(TEMPLATEPATH . '/widget-views/rpt-widget.php')) {
         // Use custom template from parent theme
         include TEMPLATEPATH . '/widget-views/rpt-widget.php';
     } else {
         // Use builtin temlate
         include RPT_DIR . 'views/client/widget.php';
     }
     wp_reset_postdata();
     echo $after_widget;
     return true;
 }
Exemplo n.º 3
0
 
                 <div class="info--overlay"><div>
                     <p class="teaser__title">
                         <?php 
             echo get_the_title($post);
             //echo ' '.get_the_ID();
             ?>
                     </p>
             
                     <p class="teaser__artist"> 
              
                          <?php 
             //////////// Find related artists of related work //////////////
             //$related_artist_pages_ids = array();
             unset($related_artist_pages_ids);
             $related_artist_pages_ids = rpt_get_object_relation($post->ID, 'artist');
             //echo print_r($related_artist_pages_ids).' ';
             //echo count($related_artist_pages_ids).' ';
             if (count($related_artist_pages_ids) >= 1) {
                 $related_artist_pages = get_posts(array('post_type' => 'artist', 'post_status' => 'publish', 'posts_per_page' => -1, 'post__in' => $related_artist_pages_ids, 'orderby' => 'post_date', 'order' => 'DESC'));
                 //echo print_r($related_artist_pages).' ';
                 foreach ($related_artist_pages as $artist_post) {
                     echo get_the_title($artist_post) . '<br />';
                 }
                 //unset($related_artist_pages_ids);
                 //$related_artist_pages_ids = array();
                 //echo count($related_artist_pages_ids);
             }
             ?>
                      
                          <?php 
 /**
  * Prints the appropriate response to a posttype quick search.
  *
  *
  * @param void
  * @author Nicolas Juen
  */
 public static function wp_ajax_posttype_quick_search()
 {
     $args = array();
     $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
     $query = isset($_REQUEST['q']) ? $_REQUEST['q'] : '';
     $response_format = isset($_REQUEST['response-format']) && in_array($_REQUEST['response-format'], array('json', 'markup')) ? $_REQUEST['response-format'] : 'json';
     $post_id = isset($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : '';
     // Ad custom walker
     if ('markup' == $response_format) {
         $args['walker'] = new Walker_Relations_Checklist();
     }
     if ((int) $post_id > 0) {
         // Get current items for checked datas.
         $current_items = rpt_get_object_relation($post_id);
         if (is_array($current_items)) {
             $current_items = array_map('intval', $current_items);
         }
         $args['current_items'] = $current_items;
         $args['current_id'] = $post_id;
     }
     $matches = array();
     if (preg_match('/quick-search-(posttype|taxonomy)-([a-zA-Z_-]*\\b)/', $type, $matches)) {
         if ('posttype' == $matches[1] && get_post_type_object($matches[2])) {
             query_posts(array('nopaging' => true, 'post_type' => $matches[2], 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', 's' => $query, 'post__not_in' => array($post_id), 'rpt_query' => true));
             if (!have_posts()) {
                 return false;
             }
             while (have_posts()) {
                 the_post();
                 if ('markup' == $response_format) {
                     // Add post_type for the walker
                     $args['post_type'] = $matches[2];
                     echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', array(get_post(get_the_ID()))), 0, (object) $args);
                 } elseif ('json' == $response_format) {
                     echo json_encode(array('ID' => get_the_ID(), 'post_title' => get_the_title(), 'post_type' => get_post_type()));
                     echo "\n";
                 }
             }
         }
     }
     die;
 }
Exemplo n.º 5
0
            <a class="thumbnail" href="<?php 
            the_permalink();
            ?>
"><?php 
            the_post_thumbnail("work-thumb");
            ?>

            <div class="info--overlay"><div>
                <div><?php 
            the_title();
            ?>
</div>
                <?php 
            unset($related_artist_pages_ids);
            $id = get_the_ID();
            $related_artist_pages_ids = rpt_get_object_relation($id, 'artist');
            if (count($related_artist_pages_ids) >= 1) {
                $related_artist_pages = get_posts(array('post_type' => 'artist', 'post_status' => 'publish', 'posts_per_page' => -1, 'post__in' => $related_artist_pages_ids, 'orderby' => 'post_date', 'order' => 'DESC'));
                //echo print_r($related_artist_pages).' ';
                foreach ($related_artist_pages as $artist_post) {
                    echo get_the_title($artist_post) . '<br />';
                }
                //unset($related_artist_pages_ids);
                //$related_artist_pages_ids = array();
                //echo count($related_artist_pages_ids);
                // wp_reset_query();
            }
            ?>
                <?php 
            // other artists
            $artists = rwmb_meta('work_artists');
 /**
  * Filtering results when rel- key word is set on WP_Query
  */
 public static function parse_query($query)
 {
     global $wpdb;
     foreach (get_post_types(array('show_ui' => true, 'public' => true), 'objects') as $post_type) {
         $key = 'rel-' . $post_type->name;
         if (isset($query->query_vars[$key]) && !empty($query->query_vars[$key])) {
             // Get ID form slug
             $post_id = (int) $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", stripslashes($query->query_vars[$key]), $post_type->name));
             if ($post_id == 0) {
                 // Post not exist for this post name ? Make zero result
                 $query->query_vars['post__in'] = array(0);
             } else {
                 // Otherwise, filtering result with this ID.
                 $query->query_vars['post__in'] = rpt_get_object_relation($post_id, array());
                 // TODO: Manage the case when the post__in field is already charged ?
             }
             $query->is_home = false;
             $query->is_archive = true;
             // TODO: Manage rewrite and title ?
         }
     }
 }
Exemplo n.º 7
0
    function field($args, $instance)
    {
        global $post;
        extract($args);
        $entries = is_array($entries) ? $entries['name'] : $entries;
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        // Get current items for checked datas.
        $current_items = rpt_get_object_relation($args['post_id'], $instance['posttype']);
        $current_items = array_map('intval', $current_items);
        $_args = array('nopaging' => true, 'order' => 'ASC', 'orderby' => 'title', 'post_type' => $instance['posttype'], 'post_status' => 'publish', 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'current_id' => $args['post_id'], 'current_items' => $current_items);
        // For the same post type, exclude current !
        $_args['post__not_in'] = array($args['post_id']);
        $post_type = get_post_type_object($instance['posttype']);
        // Default ?
        if (isset($post_type->_default_query)) {
            $_args = array_merge($_args, (array) $post_type->_default_query);
        }
        $get_posts = new WP_Query();
        $posts = $get_posts->query($_args);
        if (!$get_posts->post_count) {
            echo '<p>' . __('No items.', 'relation-post-types') . '</p>';
            return;
        }
        switch ($instance['mode']) {
            case 'multiple_checkboxes':
                $walker = new Walker_Field_Relations_Checklist();
                $start_lv = '<ul id="' . $instance['posttype'] . 'checklist" class="list:' . $instance['posttype'] . ' categorychecklist form-no-clear">';
                $end_lv = '</ul>';
                break;
            case 'simple':
                $walker = new Walker_Field_RelationsDropdown();
                $start_lv = '<select name="' . $this->get_field_name('name') . '" style="width: 47%;">';
                $end_lv = '</select>';
                break;
            case 'multiple_select':
                $walker = new Walker_Field_RelationsDropdown();
                $start_lv = '<select name="' . $this->get_field_name('name') . '[]" style="width: 47%;height: auto;" size="10" multiple>';
                $end_lv = '</select>';
                break;
            default:
                return false;
                break;
        }
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
            <div id="posttype-<?php 
        echo $instance['posttype'];
        ?>
" class="posttypediv">
                <div id="<?php 
        echo $instance['posttype'];
        ?>
-all" class="tabs-panel-view-all tabs-panel-active">
                        <?php 
        echo isset($start_lv) ? $start_lv : '';
        $_args['walker'] = $walker;
        $_args['name'] = $this->get_field_name('name');
        $checkbox_items = walk_nav_menu_tree($posts, $instance['depth'], (object) $_args);
        echo $checkbox_items;
        echo isset($end_lv) ? $end_lv : '';
        ?>
                </div><!-- /.tabs-panel -->
            </div>
            <?php 
        if (isset($instance['description']) && $instance['description'] != '') {
            echo '<p>' . $instance['description'] . '</p>';
        }
        echo $after_widget;
        /*
        
                        $post_type_name = $post_type['args']->name;
        
                    // Get current items for checked datas.
                    $current_items = rpt_get_object_relation( $object->ID );
                    $current_items = array_map( 'intval', $current_items );
        
                    // Build args for walker
                    $args = array(
                            'nopaging' 			=> true,
                            'order' 			=> 'ASC',
                            'orderby' 			=> 'title',
                            'post_type' 		=> $post_type_name,
                            'post_status' 		=> 'publish',
                            'suppress_filters' 	=> true,
                            'update_post_term_cache' => false,
                            'update_post_meta_cache' => false,
                            'current_id' 		=> $object->ID,
                            'current_items'		=> $current_items
                    );
        
                    // For the same post type, exclude current !
                    if ( $object->post_type == $post_type_name )
                            $args['post__not_in'] = array($object->ID);
        
                    // Default ?
                    if ( isset( $post_type['args']->_default_query ) )
                            $args = array_merge($args, (array) $post_type['args']->_default_query );
        
                    $get_posts = new WP_Query;
                    $posts = $get_posts->query( $args );
                    if ( ! $get_posts->post_count ) {
                            echo '<p>' . __( 'No items.', 'relation-post-types' ) . '</p>';
                            return;
                    }
        
                    $walker = new Walker_Relations_Checklist;
                    ?>
                    <div id="posttype-<?php echo $post_type_name; ?>" class="posttypediv">
                            <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all tabs-panel-active">
                                    <ul id="<?php echo $post_type_name; ?>checklist" class="list:<?php echo $post_type_name; ?> categorychecklist form-no-clear">
                                            <?php
                                            $args['walker'] = $walker;
                                            $checkbox_items = walk_nav_menu_tree( $posts, 0, (object) $args );
                                            echo $checkbox_items;
                                            ?>
                                    </ul>
                            </div><!-- /.tabs-panel -->
                    </div><!-- /.posttypediv -->
        
                    <input type="hidden" name="post-relation-post-types" value="1" />
                    <?php
        */
    }
Exemplo n.º 8
0
<?php

/* 
Author of Sample :
	Mateus Reis
	mateus@laboratorio72.com
	skype: mateusreis
*/
$artists_relation = rpt_get_object_relation($id_post, 'artista');
if (count($artists_relation) >= 1) {
    global $post;
    $args = array('post_type' => 'artista', 'post_status' => 'publish', 'posts_per_page' => -1, 'showposts' => -1, 'post__in' => $artists_relation, 'orderby' => 'date', 'order' => 'DESC');
    $results_artists = query_posts($args);
    echo '<ul>' . "\n";
    foreach ($results_artists as $post) {
        // stuff
        echo '<li><a href="' . get_permalink($post) . '">' . get_the_title() . '</a></li>' . "\n";
    }
    echo '</ul>' . "\n";
}