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