Получить теги записей в Grid Builder Visual Composer - PullRequest
0 голосов
/ 13 апреля 2020

Я пытаюсь вывести теги записей в построителе пользовательских сеток, он позволяет выводить значения пользовательских метаполей по ключам, но не позволяет использовать простые теги wp. Я пытался следовать инструкциям , и вот мой код, который добавил шорткод, но все еще не выводит никаких тегов

add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
 $shortcodes['vc_mytags'] = array(
  'name' => __( 'My Tags', 'my-text-domain' ),
  'base' => 'vc_mytags',
  'category' => __( 'Post', 'my-text-domain' ),
  'description' => __( 'Show post tags', 'my-text-domain' ),
  'post_type' => Vc_Grid_Item_Editor::postType(),
 );

 return $shortcodes;
}
// output function
add_shortcode( 'vc_mytags', 'vc_mytags_render' );
function vc_mytags_render($atts, $content, $tag) {
 return '{{ mytags }}';
}

add_filter( 'vc_gitem_template_attribute_mytags', 'vc_gitem_template_attribute_mytags ', 10, 2 );
function vc_gitem_template_attribute_mytags( $value, $data ) {
 /**
  * @var Wp_Post $post
  * @var string $data
  */
 extract( array_merge( array(
  'post' => null,
  'data' => '',
 ), $data ) );

 return var_export( get_the_tag_list('<p>Tags: ',', ','</p>'));
}

Что не так?

1 Ответ

0 голосов
/ 13 апреля 2020

Вот рабочий код

add_filter('vc_gitem_template_attribute_mytags','vc_gitem_template_attribute_mytags', 10, 2 );
function vc_gitem_template_attribute_mytags( $value, $data ) {
    extract( array_merge( array(
      'post' => null,
      'data' => '',
   ), $data ) );
  $atts_extended = array();
  parse_str( $data, $atts_extended );
  $atts = $atts_extended['atts'];
  // write all your widget code in here using queries etc
$mytags = get_the_tag_list('<p>Tags: ',', ','</p>');
 return $mytags;
}

add_filter( 'vc_grid_item_shortcodes', 'mytags_shortcodes' );
function mytags_shortcodes( $shortcodes ) {
   $shortcodes['vc_mytags'] = array(
     'name' => __( 'Tags', 'sage' ),
     'base' => 'vc_mytags',
     'category' => __( 'Content', 'sage' ),
     'description' => __( 'Displays tags', 'sage' ),
     'post_type' => Vc_Grid_Item_Editor::postType()
  );
  return $shortcodes;
 }

add_shortcode( 'vc_mytags', 'vc_mytags_render' );
function vc_mytags_render($atts){
   $atts = vc_map_get_attributes( 'vc_mytags', $atts );
   return '{{ mytags }}';
}
...