我的网站上有两种帖子类型。一个用于课程,另一个用于教师。我想将教师职位类型的可选列表放在课程职位类型中,然后在课程单页中显示,并将其链接到该教师的单页。我该怎么办?
function custom_meta_box_markup($object)
{
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<div>
<select name="meta-box-dropdown">
<?php
$args=array(\'post_type\'=>\'mama_ashpaz\');
$q=new WP_Query($args);
if($q->have_posts()){
$current=0;
while($q->have_posts()){
$q->the_post();?>
<?php $options[$current]=get_the_title();
$options_id[$current]=get_the_id();
$current++;
}
}wp_reset_postdata();
foreach($options as $key=>$value){
if($value == get_post_meta($object->ID, "meta-box-dropdown", true))
{
?>
<option selected><?php echo $value; ?></option>
<?php
}
else
{
?>
<option><?php echo $value; ?></option>
<?php
}
}
?>
</select>
</div>
<?php
}
function add_custom_meta_box()
{
add_meta_box("demo-meta-box", "مامان آشپز", "custom_meta_box_markup",
"product", "side", "high", null);
}
add_action("add_meta_boxes", "add_custom_meta_box");
function save_custom_meta_box($post_id, $post, $update)
{
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-
box-nonce"], basename(__FILE__)))
return $post_id;
if(!current_user_can("edit_post", $post_id))
return $post_id;
if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
return $post_id;
$slug = "product";
if($slug != $post->post_type)
return $post_id;
$meta_box_dropdown_value = "";
if(isset($_POST["meta-box-dropdown"]))
{
$meta_box_dropdown_value = $_POST["meta-box-dropdown"];
}
update_post_meta($post_id, "meta-box-dropdown",
$meta_box_dropdown_value);
}
add_action("save_post", "save_custom_meta_box", 10, 3);
function add_maman(){?>
<div class="maman-meta"><a href="<?php echo get_the_permalink();?>">
<?php echo get_post_meta( get_the_id(), "meta-box-dropdown", true ) ;?>
</a>
</div>
<?php
}
add_action( \'woocommerce_before_single_product_summary\',\'add_maman\' );