最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - Foreach result into WP_query

programmeradmin0浏览0评论

I know it may sound very strange as a question, but I would like to know if it is possible to insert the result of a foreach in WP_query

How:

I would like to avoid doing the maintenance manually that every custom post type created must add the name of the custom post type to the post_type query, to be clear:

'post_type' => array('CUSTOM_POST_TYPE_ONE,CUSTOM_POST_TYPE_TWO'),

but instead get me the whole list of custom post types:

<?php
$args = array(
    'public'   => true,
    '_builtin' => false
);

$output = 'names'; // 'names' or 'objects' (default: 'names')
$operator = 'and'; // 'and' or 'or' (default: 'and')

$post_types = get_post_types( $args, $output, $operator );
echo $post_types;
if ( $post_types ) { // If there are any custom public post types.

    echo '<ul>';

    foreach ( $post_types  as $post_type ) {
        echo '<li>' . $post_type . '</li>';
    }

    echo '<ul>';

}
?>

and insert it into:

'post_type' =>

so that every time I create a custom post type I get a dynamic query

发布评论

评论列表(0)

  1. 暂无评论