本文整理汇总了PHP中wpcf_pr_get_belongs函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf_pr_get_belongs函数的具体用法?PHP wpcf_pr_get_belongs怎么用?PHP wpcf_pr_get_belongs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf_pr_get_belongs函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpv_before_display_post_post_relationship
function wpv_before_display_post_post_relationship($post, $view_id)
{
static $related = array();
global $WP_Views;
if (function_exists('wpcf_pr_get_belongs')) {
if (!isset($related[$post->post_type])) {
$related[$post->post_type] = wpcf_pr_get_belongs($post->post_type);
}
if (is_array($related[$post->post_type])) {
foreach ($related[$post->post_type] as $post_type => $data) {
$related_id = wpcf_pr_post_get_belongs($post->ID, $post_type);
if ($related_id) {
$WP_Views->set_variable($post_type . '_id', $related_id);
}
}
}
}
}
示例2: generate_checksum
/**
* Generates checksums for defined content types.
*
* @param type $type
* @param type $item_id
* @return type
*/
function generate_checksum($type, $item_id = null)
{
switch ($type) {
case 'group':
$checksum = wpcf_admin_fields_get_group($item_id);
$checksum['meta'] = $this->get_group_meta($item_id);
ksort($checksum['meta']);
break;
case 'field':
$checksum = wpcf_admin_fields_get_field($item_id);
break;
case 'custom_post_type':
$checksum = wpcf_get_custom_post_type_settings($item_id);
$checksum['relationship_settings']['has'] = wpcf_pr_get_has($item_id);
if (is_array($checksum['relationship_settings']['has'])) {
ksort($checksum['relationship_settings']['has']);
}
$checksum['relationship_settings']['belongs'] = wpcf_pr_get_belongs($item_id);
if (is_array($checksum['relationship_settings']['belongs'])) {
ksort($checksum['relationship_settings']['belongs']);
}
break;
case 'custom_taxonomy':
$checksum = wpcf_get_custom_taxonomy_settings($item_id);
break;
default:
/*
* Enable $this->generate_checksum('test');
*/
$checksum = $type;
break;
}
// Unset various not wanted data
foreach ($this->_remove_data_keys as $key) {
if (isset($checksum[$key])) {
unset($checksum[$key]);
}
}
if (is_array($checksum)) {
ksort($checksum);
}
// debug( $checksum, false );
return md5(maybe_serialize($checksum));
}
示例3: record_post_relationship_belongs
function record_post_relationship_belongs($content)
{
global $post;
$this->post_relationship_depth = $this->post_relationship_depth + 1;
if (!empty($post->ID) && function_exists('wpcf_pr_get_belongs')) {
if (!isset($this->relations[$post->post_type])) {
$this->relations[$post->post_type] = wpcf_pr_get_belongs($post->post_type);
}
if (is_array($this->relations[$post->post_type])) {
foreach ($this->relations[$post->post_type] as $post_type => $data) {
$related_id = wpcf_pr_post_get_belongs($post->ID, $post_type);
if ($related_id) {
$this->post_relationship['$' . $post_type . '_id'] = $related_id;
} else {
$this->post_relationship['$' . $post_type . '_id'] = 0;
}
}
}
}
$this->post_relationship_track[$this->post_relationship_depth] = $this->post_relationship;
return $content;
}
示例4: wpv_shortcode_wpv_control_item
function wpv_shortcode_wpv_control_item( $atts, $value ) {
global $sitepress;
// First control checks
if ( !function_exists( 'wpcf_pr_get_belongs' ) ) {
return __( 'You need the Types plugin to render this parametric search control', 'wpv-views' );
}
if ( !isset( $atts['url_param'] ) || empty( $atts['url_param'] ) ) {
return __('The url_param argument is missing from the wpv-control-set shortcode.', 'wpv-views');
}
if ( !isset( $atts['type'] ) || empty( $atts['type'] ) ) {
return __('The type argument needs to be set in the wpv-control-item shortcode.', 'wpv-views');
}
if ( !isset( $atts['ancestor_type'] ) || empty( $atts['ancestor_type'] ) ) {
return __('The ancestor_type argument is missing from the wpv-control-item shortcode.', 'wpv-views');
}
if ( !isset( $atts['ancestor_tree'] ) || empty( $atts['ancestor_tree'] ) ) {
return __('The ancestors argument is missing from the wpv-control-set shortcode.', 'wpv-views');
}
if ( !isset( $atts['returned_pt_parents'] ) || empty( $atts['returned_pt_parents'] ) ) {
return __('The post types listed in this View do not have ancestors.', 'wpv-views');
}
extract(
shortcode_atts( array(
'type' => '', // select, multi-select, checbox, checkboxes, radio/radios, date/datepicker, textfield
'url_param' => '', // URL parameter to be used
'ancestor_type' => '',
'ancestor_tree' => '',
'default_label' => '',
'returned_pt' => '',
'returned_pt_parents' => '',
'format' => false,
'orderby' => 'title', // can be any key of $allowed_orderby_values
'order' => 'ASC', // ASC or DESC
'style' => '', // inline styles for input
'class' => '', // input classes
'label_style' => '', // inline styles for input label
'label_class' => '' // classes for input label
), $atts)
);
$style = esc_attr( $style );
$class = esc_attr( $class );
$label_style = esc_attr( $label_style );
$label_class = esc_attr( $label_class );
$ancestor_tree_array = explode( '>', $ancestor_tree ); // NOTE this makes it useful for just one-branch scenarios, might extend this
if ( !in_array( $ancestor_type, $ancestor_tree_array ) ) {
return __( 'The ancestor_type argument refers to a post type that is not included in the ancestors tree.', 'wpv-views' );
}
global $wpdb, $WP_Views;
$return = '';
$this_type_parent_classes = array();
$returned_post_types = explode( ',', $returned_pt );
$returned_post_type_parents = explode( ',', $returned_pt_parents );
$filter_full_list = false;
$this_tree_ground = end( $ancestor_tree_array );
$this_tree_roof = reset( $ancestor_tree_array );
if ( !in_array( $this_tree_ground, $returned_post_type_parents ) ) {
return __( 'The ancestors argument does not end with a valid parent for the returned post types on this View.', 'wpv-views' );
}
if ( !empty( $default_label ) ) {
$aux_array = $WP_Views->view_used_ids;
$view_name = get_post_field( 'post_name', end($aux_array));
$default_label = wpv_translate( $ancestor_type . '_default_label', $default_label, false, 'View ' . $view_name );
}
// Validate order and orderby arguments for SQL query (ignore invalid values).
// Allowed values and their translation into names of wp_posts columns.
$allowed_orderby_values = array(
'id' => 'ID',
'title' => 'post_title',
'date' => 'post_date',
'date_modified' => 'post_modified',
'comment_count' => 'comment_count' );
if( ! isset( $allowed_orderby_values[ $orderby ] ) ) {
$orderby = 'title';
}
// Now $orderby contains a valid column name at all times.
$orderby = $allowed_orderby_values[ $orderby ];
// Default to ASC on invalid $order value.
$order = ( 'DESC' == strtoupper( $order ) ) ? 'DESC' : 'ASC';
$view_settings = $WP_Views->get_view_settings();
$dependant = false;
$counters = false;
$empty_action = array();
if ( isset( $view_settings['dps'] ) && is_array( $view_settings['dps'] ) && isset( $view_settings['dps']['enable_dependency'] ) && $view_settings['dps']['enable_dependency'] == 'enable' ) {
$dependant = true;
$force_disable_dependant = $WP_Views->get_force_disable_dependant_parametric_search();
if ( $force_disable_dependant ) {
$dependant = false;
}
}
if ( $format && strpos( $format, '%%COUNT%%' ) !== false ) {
$counters = true;
}
//.........这里部分代码省略.........
示例5: WPV_wpcf_record_post_relationship_belongs
function WPV_wpcf_record_post_relationship_belongs($content)
{
global $post, $WPV_wpcf_post_relationship, $WPV_wpcf_post_relationship_depth, $WPV_wpcf_post_relationship_track;
static $related = array();
$WPV_wpcf_post_relationship_depth++;
if (!empty($post->ID) && function_exists('wpcf_pr_get_belongs')) {
if (!isset($related[$post->post_type])) {
$related[$post->post_type] = wpcf_pr_get_belongs($post->post_type);
}
if (is_array($related[$post->post_type])) {
foreach ($related[$post->post_type] as $post_type => $data) {
$related_id = wpcf_pr_post_get_belongs($post->ID, $post_type);
if ($related_id) {
$WPV_wpcf_post_relationship['$' . $post_type . '_id'] = $related_id;
} else {
$WPV_wpcf_post_relationship['$' . $post_type . '_id'] = 0;
}
}
}
}
$WPV_wpcf_post_relationship_track[$WPV_wpcf_post_relationship_depth] = $WPV_wpcf_post_relationship;
return $content;
}
示例6: WPV_wpcf_record_post_relationship_belongs
function WPV_wpcf_record_post_relationship_belongs($content)
{
global $post, $WPV_wpcf_post_relationship;
static $related = array();
if (function_exists('wpcf_pr_get_belongs')) {
if (!isset($related[$post->post_type])) {
$related[$post->post_type] = wpcf_pr_get_belongs($post->post_type);
}
if (is_array($related[$post->post_type])) {
foreach ($related[$post->post_type] as $post_type => $data) {
$related_id = wpcf_pr_post_get_belongs($post->ID, $post_type);
if ($related_id) {
$WPV_wpcf_post_relationship['$' . $post_type . '_id'] = $related_id;
}
}
}
}
return $content;
}
示例7: add_view_template_parent_groups
function add_view_template_parent_groups($items)
{
global $post;
// get current View ID
$view_template_id = $post->ID;
// get all view templates attached in the Settings page for single view
$view_template_relations = $this->get_view_template_settings();
// find view template groups and get their parents
$current_types = array();
$parent_types = array();
foreach ($view_template_relations as $relation => $value) {
if ($value == $view_template_id) {
$current_types[] = $relation;
if (function_exists('wpcf_pr_get_belongs')) {
$parent_types[] = wpcf_pr_get_belongs($relation);
}
}
}
// get parent groups
$all_parent_groups = array();
foreach ($parent_types as $type) {
foreach ($type as $typename => $typeval) {
$parent_groups = wpcf_admin_get_groups_by_post_type($typename);
}
}
}
示例8: wpv_filter_extend_query_for_parametric_and_counters
//.........这里部分代码省略.........
$view_settings_defaults = array('post_type' => 'any', 'orderby' => 'post-date', 'order' => 'DESC', 'paged' => '1', 'posts_per_page' => -1);
extract($view_settings_defaults);
$view_settings['view_id'] = $id;
extract($view_settings, EXTR_OVERWRITE);
$query = array('posts_per_page' => $posts_per_page, 'paged' => $paged, 'post_type' => $post_type, 'order' => $order, 'suppress_filters' => false, 'ignore_sticky_posts' => true);
// Add special check for media (attachments) as their default status in not usually published
if (sizeof($post_type) == 1 && $post_type[0] == 'attachment') {
$query['post_status'] = 'any';
// Note this can be overriden by adding a status filter.
}
$query = apply_filters('wpv_filter_query', $query, $view_settings, $id);
// Now we have the $query as in the original one
// We now need to overwrite the limit, offset, paged and pagination options
// Also, we set it to just return the IDs
$query['posts_per_page'] = -1;
$query['ĺimit'] = -1;
$query['paged'] = 1;
$query['offset'] = 0;
$query['fields'] = 'ids';
if ($cache_exclude_queried_posts) {
// do not query again already queried and cached posts
$already = array();
if (isset($post_query->posts) && !empty($post_query->posts)) {
foreach ((array) $post_query->posts as $post_object) {
$already[] = $post_object->ID;
}
}
$WP_Views->returned_ids_for_parametric_search = $already;
if (isset($query['pr_filter_post__in'])) {
$query['post__in'] = $query['pr_filter_post__in'];
} else {
// If just for the missing ones, generate the post__not_in argument
if (isset($query['post__not_in'])) {
$query['post__not_in'] = array_merge((array) $query['post__not_in'], (array) $already);
} else {
$query['post__not_in'] = (array) $already;
}
// And adjust on the post__in argument
if (isset($query['post__in'])) {
$query['post__in'] = array_diff((array) $query['post__in'], (array) $query['post__not_in']);
//unset( $query['post__in'] );
}
}
}
// Perform the query
$aux_cache_query = new WP_Query($query);
// In case we need to recreate our own cache object, we do not need to load there all the postmeta and taxonomy data, just for the elements involved in parametric search controls
$filter_c_mode = isset($view_settings['filter_controls_mode']) && is_array($view_settings['filter_controls_mode']) ? $view_settings['filter_controls_mode'] : array();
$filter_c_name = isset($view_settings['filter_controls_field_name']) && is_array($view_settings['filter_controls_field_name']) ? $view_settings['filter_controls_field_name'] : array();
$f_taxes = array();
$f_fields = array();
foreach ($filter_c_mode as $f_index => $f_mode) {
if (isset($filter_c_name[$f_index])) {
switch ($f_mode) {
case 'slug':
$f_taxes[] = $filter_c_name[$f_index];
break;
case 'cf':
$f_fields[] = $filter_c_name[$f_index];
break;
case 'rel':
if (function_exists('wpcf_pr_get_belongs')) {
$returned_post_types = $view_settings['post_type'];
$returned_post_type_parents = array();
if (empty($returned_post_types)) {
$returned_post_types = array('any');
}
foreach ($returned_post_types as $returned_post_type_slug) {
$parent_parents_array = wpcf_pr_get_belongs($returned_post_type_slug);
if ($parent_parents_array != false && is_array($parent_parents_array)) {
$returned_post_type_parents = array_merge($returned_post_type_parents, array_values(array_keys($parent_parents_array)));
}
}
foreach ($returned_post_type_parents as $parent_to_cache) {
$f_fields[] = '_wpcf_belongs_' . $parent_to_cache . '_id';
}
}
break;
default:
break;
}
}
}
// If we are using the native caching, update the cache for the posts returned by the aux query
if (is_array($aux_cache_query->posts) && !empty($aux_cache_query->posts)) {
$WP_Views->returned_ids_for_parametric_search = array_merge($WP_Views->returned_ids_for_parametric_search, $aux_cache_query->posts);
$WP_Views->returned_ids_for_parametric_search = array_unique($WP_Views->returned_ids_for_parametric_search);
if ($cache_use_native) {
// If we are using the native caching, update the cache for the posts returned by the aux query
update_postmeta_cache($aux_cache_query->posts);
update_object_term_cache($aux_cache_query->posts, $view_settings['post_type']);
} else {
// Else, we need to fake an $wp_object_cache->cache
$f_data = array('cf' => $f_fields, 'tax' => $f_taxes);
$cache_combined = wpv_custom_cache_metadata($aux_cache_query->posts, $f_data);
$wp_object_cache->cache = $cache_combined;
}
}
return $post_query;
}
示例9: wpv_ajax_wpv_get_post_relationship_info
function wpv_ajax_wpv_get_post_relationship_info()
{
if (wp_verify_nonce($_POST['wpv_nonce'], 'wpv_get_posts_select_nonce')) {
if (function_exists('wpcf_pr_get_belongs') && isset($_POST['post_types'])) {
$post_types = get_post_types('', 'objects');
$output_done = false;
foreach ($_POST['post_types'] as $post_type) {
$related = wpcf_pr_get_belongs($post_type);
if ($related === false) {
echo sprintf(__('Post type <strong>%s</strong> doesn\'t belong to any other post type', 'wpv-views'), $post_types[$post_type]->labels->singular_name, $related);
echo '<br />';
$output_done = true;
}
if (is_array($related) && count($related)) {
$keys = array_keys($related);
$related = array();
foreach ($keys as $key) {
$related[] = $post_types[$key]->labels->singular_name;
}
}
if (is_array($related) && count($related) == 1) {
$related = implode(', ', $related);
echo sprintf(__('Post type <strong>%s</strong> is a child of <strong>%s</strong> post type', 'wpv-views'), $post_types[$post_type]->labels->singular_name, $related);
echo '<br />';
$output_done = true;
}
if (is_array($related) && count($related) > 1) {
$last = array_pop($related);
$related = implode(', ', $related);
$related .= __(' and ') . $last;
echo sprintf(__('Post type <strong>%s</strong> is a child of <strong>%s</strong> post types', 'wpv-views'), $post_types[$post_type]->labels->singular_name, $related);
echo '<br />';
$output_done = true;
}
}
if ($output_done) {
echo '<br />';
}
}
}
die;
}