我正在运行BeTheme,但添加了自定义文章类型。在index.php上,我需要从常规文章和我创建的自定义文章类型“latest-news”中抽取。我不知道如何设置它,以便index.php从我的帖子和我的自定义帖子类型中提取。
在我的主题,index.php文件是从该模板文件中的函数拉动,https://github.com/pingram3541/betheme/blob/master/includes/content-post.php
在部分开始对这个文件的第10行:
if(! function_exists('mfn_content_post')){
function mfn_content_post($query = false, $style = false, $images_only = false){
global $wp_query;
我敢肯定我需要改变什么$args
变量$wp_query
正在拉动,所以array('post_type' => array('post')
也有'latest-news'
但我不知道在哪里可以找到这个,或者如果这甚至是正确的方法。
编辑: 我只是想添加以下代码functions.php
:
function add_custom_post_type_to_query($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('post_type', array('post', 'latest-news'));
}
}
add_action('pre_get_posts', 'add_custom_post_type_to_query');
这没有奏效。
这是正确的做法。你是否希望你的新查询搜索普通帖子或只有自定义帖子类型? –
两者。理想情况下,它会从“发布”和“最新新闻”发布类型以及按日期排序。 – user3183717