以下功能用于加载我的自定义帖子类型帖子。问题是它没有加载get_post_meta数据。我在我的functions.php文件中有这个。我是否需要在get_post_meta中添加一些内容,因为它位于函数文件中?
function get_latest_post(){
global $wpdb;
$num=$_POST['numposts'];
$id = $_POST['id'];
$id = split('page',$id);
$id = str_replace('/','',$id[1]);
if($id!=0)
{
$offst = $id*$num-$num;
}else $offst=0;
$wp_query = new WP_Query(); $wp_query->query('post_type=video_posts&orderby=date&posts_per_page='.$num.'&offset='.$offst);
if($wp_query->have_posts()) : $i = 1; while ($wp_query->have_posts()) : $wp_query->the_post();?>
<?php $embeds = get_post_meta($post->ID, 'rm_video_embed_code'); ?>
<?php $thumbnail_id = get_the_post_thumbnail($post->ID);
preg_match ('/src="(.*)" class/',$thumbnail_id,$link);
if(!empty($thumbnail_id)) {
$image_path = thumbGen($link[1],190,0,"crop=1&halign=center&valign=center&return=1");
$image_all = get_bloginfo('url').$image_path;
$my_image = array_values(getimagesize($image_all));
list($width, $height, $type, $attr) = $my_image;
}
?>
<div class="pop_<?php echo $i; ?>" style="display:none;"><div class="bClose"></div>
<?php foreach($embeds as $embed) { echo $embed; }?>
</div>
<?php if(has_post_thumbnail()) : ?>
<li><a href="javascript:void(0);" class="video_popup_<?php echo $i; ?>" title="<?php the_title(); ?>">
<div class="video_title"><?php the_title(); ?></div>
<div class="video_description"><?php the_content(); ?></div>
<div><img src="<?php echo $image_path; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" /></div>
<div class="clear"></div>
</a></li>
<?php endif; ?>
<?php $i++; endwhile; ?>
<?php endif; //wp_reset_query();
if((1==1)===FALSE){
echo "Oops! System error!";
}
else {
}
die();
}
add_action('wp_ajax_get_latest_post', 'get_latest_post');
add_action('wp_ajax_nopriv_get_latest_post', 'get_latest_post');
答案 0 :(得分:0)
将此添加到函数global $post;