Taxonomy Query
Always use
get_posts()
for sidequeries.query_posts()
is only for the Main query andnew WP_Query()
should be used for the second queries only. Read more here.
You can query posts by a taxonomy (category, term, etc.):
$cat_posts = new WP_Query( array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'movie_janner',
'field' => 'slug',
'terms' => array( 'action', 'commedy' )
),
array(
'taxonomy' => 'actor',
'field' => 'id',
'terms' => array( 103, 115, 206 ),
'operator' => 'NOT IN'
)
)
) );
Shortcode Query
You could also, if you want to query by shortcode, add/remove a filter on the query for the content.
Make shure that you read the comments carefully!
function wpse49871_shortcode_query_filter( $where )
{
global $wpdb;
// Lets be on the safe side, escape and such.
$new_where = $wpdb->prepare(
"%s AND %s LIKE %s"
,$where
,"{$wpdb->posts}.post_content"
// If you know the exact ID, then just insert it in here.
,like_escape( '%fileurl=%' )
);
return $new_where;
}
function wpse49871_get_shortcode_posts()
{
add_filter( 'posts_where', 'wpse_shortcode_query_filter' );
$posts = get_posts( array(
// Do your query in here. See "Taxonomy Query" args above for example
) );
// Don't need it anymore after this run
remove_filter( 'posts_where', 'wpse_shortcode_query_filter' );
return $posts;
}
An even better approach may be to wrap it up in a class like the one shown in the other Q.