我已经阅读了关于这个主题的几个问题,但没有一个是我所追求的。
我正在尝试为自定义帖子类型I创建一个短代码。我想一次显示一个帖子类型,用户可以在短代码中按类别选择。
e.g。 [feature-diagram class_name =" snake"]
这是我到目前为止的代码。我能够打印正确帖子的ID和标题,但我无法看到我为帖子类型添加的任何自定义字段(即转发器,feature_description等)。
这是我的代码..我错过了什么吗?
add_shortcode( 'feature-diagram' , 'feature_diagrams_function');
function feature_diagrams_function( $atts ) {
ob_start();
extract( shortcode_atts( array (
'type' => 'feature_diagrams',
'category' => '',
'caller_get_posts' => 1,
), $atts ) );
$options = array (
'type' => $type,
'category_name' => $category,
);
$query = new WP_Query( $options );
if ( $query->have_posts() ) { ?>
<div class="feature-image">
<div class="flex">
<div class="f1">
<p><?php the_ID(); ?></p>
<p><?php the_title(); ?></p>
<?php
// check if the repeater field has rows of data
if( have_rows('features_left') ):
?><p>Has rows</p><?php
// loop through the rows of data
while ( have_rows('features_left') ) : the_row();
?>
<div class="feature left" id="feature-<?php echo get_row_index(); ?>">
<div class="icon"><img src="<?php the_sub_field('feature_icon'); ?>"></div>
<div class="feature-text">
<div class="title" ><?php the_sub_field('feature_title'); ?></div>
<div class="description"><?php the_sub_field('feature_description'); ?></div>
<div class="middle-image"><?php the_sub_field('middle_feature_image'); ?></div>
</div>
</div>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div><!-- f1 -->
<div class="f1">
</div><!-- f1 -->
<div class="f1">
<?php
// check if the repeater field has rows of data
if( have_rows('features_right') ):
// loop through the rows of data
while ( have_rows('features_right') ) : the_row();
?>
<div class="feature right" id="feature-<?php echo get_row_index(); ?>">
<div class="icon"><img src="<?php the_sub_field('feature_icon'); ?>"></div>
<div class="feature-text">
<div class="title"><?php the_sub_field('feature_title'); ?></div>
<div class="description"><?php the_sub_field('feature_description'); ?></div>
<div class="middle-image"><?php the_sub_field('middle_feature_image'); ?></div>
</div>
</div>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div><!-- f1 -->
</div><!-- flex -->
</div><!-- Featured Image -->
<?php
$myvariable = ob_get_clean();
return $myvariable;
}
}