我正在开发一个网站 see here我创建了一个名为“项目”的自定义帖子类型。
当页面最初加载时,一切正常,所有帖子数据都已加载。但是,当我使用 $.load()
从外部文件加载相同的代码时,不会显示任何内容。这似乎只是自定义帖子类型的问题,如果我用“帖子”(默认类型)替换“项目”,则会重新查询“Hello World”帖子,但不会重新查询“项目”。
如何查询自定义帖子类型两次?这是我的代码:
<?php
$args = array(
'post_type' => 'projects',
'tax_query' => array(
'taxonomy' => 'nonfiction'
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ):
while ( $query->have_posts() ):
$query->the_post();
$meta_data = array(
'author' => get_post_meta($post->ID, 'Author', true),
'publisher' => get_post_meta($post->ID, 'Publisher', true),
'year' => get_post_meta($post->ID, 'Year', true),
'role' => get_post_meta($post->ID, 'Role', true),
'location' => get_post_meta($post->ID, 'Location', true)
);
?>
<li>
<?php
echo $meta_data['author'];
echo ". ";
the_title();
echo " (" . $meta_data['location'] . ": " . $meta_data['publisher'] . ", " . $meta_data['year'] . "). " . $meta_data['role'];
?>
</li>
<?php
endwhile;
endif;
?>
$(document).ready(function(){
$('.tab').click(function(){
$('.publications').load('http://greyediting201.staging.wpengine.com/wp-content/themes/pp_boot/_nonfiction.php', null, console.log('finished'));
});
});
最佳答案
是的,在.load()函数中不使用服务器url,而是使用相对路径,例如./js文件夹的路径/js file.js。希望它对你有用
关于javascript - 使用 jQuery.load() 查询自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28208550/