Wordpress 如何从站点中的所有自定义帖子类型获取最新帖子
我在wordpress安装中定义了多种自定义帖子类型。我想从所有自定义帖子类型中获取最新帖子。我查看的所有资源和教程都只描述了从一个自定义帖子类型获取最新帖子,而不是从多个自定义帖子类型获取最新帖子。Wordpress 如何从站点中的所有自定义帖子类型获取最新帖子,wordpress,Wordpress,我在wordpress安装中定义了多种自定义帖子类型。我想从所有自定义帖子类型中获取最新帖子。我查看的所有资源和教程都只描述了从一个自定义帖子类型获取最新帖子,而不是从多个自定义帖子类型获取最新帖子。 有没有办法做到这一点?例如,在WP_Query objects或WP_get_recent_posts()函数中为post_type属性指定多个值?如果答案是肯定的,那么具体怎么做。 任何帮助都将不胜感激。首先我想澄清的是,我不知道WordPress,但我可以帮助您进行SQL查询 我假设您的表中有
有没有办法做到这一点?例如,在WP_Query objects或WP_get_recent_posts()函数中为post_type属性指定多个值?如果答案是肯定的,那么具体怎么做。
任何帮助都将不胜感激。首先我想澄清的是,我不知道WordPress,但我可以帮助您进行SQL查询 我假设您的表中有日期时间列
select * from table name
where column name in (here write all your different types followed by comma )
order by your date time column name desc;
例如
首先我想澄清的是,我不知道WordPress,但我可以帮助您进行SQL查询 我假设您的表中有日期时间列
select * from table name
where column name in (here write all your different types followed by comma )
order by your date time column name desc;
例如
它将从多个自定义帖子类型中获取帖子
query_posts( array(
'post_type' => array( 'custom_post1', 'custom_post2', 'custom_post3',
'custom_post4' ),
'cat' => 3,
'showposts' => 5 )
);
它将从多个自定义帖子类型中获取帖子
query_posts( array(
'post_type' => array( 'custom_post1', 'custom_post2', 'custom_post3',
'custom_post4' ),
'cat' => 3,
'showposts' => 5 )
);
让我们获取您的所有自定义帖子类型
$args = array('public' => true, '_builtin' => false);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
$post_types
现在是一个包含所有自定义post类型名称的数组。您的所有帖子查询应该是这样的
$allposts = array( 'posts_per_page' => -1,
'post_type'=> $post_types,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query( $allposts );
if ( $query->have_posts() ) :
while ($query-> have_posts()) : $query -> the_post()
the_permalink();
the_title();
the_content();
endwhile;
endif;
让我们获取您的所有自定义帖子类型
$args = array('public' => true, '_builtin' => false);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
$post_types
现在是一个包含所有自定义post类型名称的数组。您的所有帖子查询应该是这样的
$allposts = array( 'posts_per_page' => -1,
'post_type'=> $post_types,
'orderby' => 'date',
'order' => 'DESC'
);
$query = new WP_Query( $allposts );
if ( $query->have_posts() ) :
while ($query-> have_posts()) : $query -> the_post()
the_permalink();
the_title();
the_content();
endwhile;
endif;