I'm working on a Wordpress plugin. For ease of use I would like to add some parameters to a shortcode that will modify my custom post type query. I have it working, but it clearly isn't the best way to do it. I'd be much obliged if somebody could show me a more efficient way to accomplish the same thing! Thanks!
extract(shortcode_atts(array(
'type' => '',
), $atts));
if ($type)
{
$args = array(
'orderby'=>'title',
'order'=>'ASC',
'post_type' => 'my_post_type',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'slug',
'terms' => $type,
),
),
);
}
else
{
$args = array(
'orderby'=>'title',
'order'=>'ASC',
'post_type' => 'my_post_type',
'posts_per_page' => -1,
);
}
$items = get_posts($args);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire