WordPress快捷码添加分类属性
我有一个“员工”的自定义职位类型。该职位类型具有“职位”(医生、护士等)分类。我试图创建一个短代码,允许用户只返回页面上特定分类法的人员 例如:WordPress快捷码添加分类属性,wordpress,taxonomy,custom-post-type,shortcode,Wordpress,Taxonomy,Custom Post Type,Shortcode,我有一个“员工”的自定义职位类型。该职位类型具有“职位”(医生、护士等)分类。我试图创建一个短代码,允许用户只返回页面上特定分类法的人员 例如: [staff position="doctors"] 我试着按照一些教程,但似乎不能得到这个工作。这是我到目前为止拥有的返回所有员工的代码 function get_staff($atts) { $loop = new WP_Query( array ( 'post_type' => 'staff',
[staff position="doctors"]
我试着按照一些教程,但似乎不能得到这个工作。这是我到目前为止拥有的返回所有员工的代码
function get_staff($atts) {
$loop = new WP_Query(
array (
'post_type' => 'staff',
'orderby' => 'title'
)
);
if ($loop->have_posts()) {
$output = '<div class="staff">';
while($loop->have_posts()){
$loop->the_post();
$meta = get_post_meta(get_the_id());
$output .= '
<div class="staff" style="float: left; display: block; border: 1px solid #CCC; margin: 10px; padding: 12px; background-color: #eee;">
<a href="' . get_permalink() . '">
' . get_the_post_thumbnail($post->ID, 'thumbnail') . '<br />
' . get_the_title() . '</a><br />
' . get_the_excerpt() . '
</div>
';
}
$output .= "</div>";
} else {
$output = 'No Staff Added Yet.';
}
return $output;
};
add_shortcode('staff', 'get_staff');
功能获取工作人员($atts){
$loop=新的WP\U查询(
排列(
“职位类型”=>“员工”,
'orderby'=>'标题'
)
);
如果($loop->have_posts()){
$output='';
而($loop->have_posts()){
$loop->the_post();
$meta=get_post_meta(get_id());
$output.='
“.获取摘录()
';
}
$output.=“”;
}否则{
$output='尚未添加员工';
}
返回$output;
};
添加快捷码(“staff”,“get_staff”);
感谢您提供的任何帮助。您需要将其添加到您的查询中
extract( shortcode_atts( array( 'position' => 'doctors' ), $atts ) ); // $position variable will be initialized to 'doctors' if the shortcode is missing the 'position' parameter
$loop = new WP_Query(
array (
'post_type' => 'staff',
'orderby' => 'title',
'position' => $position
)
);