I think I have to pass parameter of shortcode, but how I do
Yes, that’s correct, and you already are passing the parameter to your shortcode when you do [arts-list type=10]
— although you should enclose the parameter value in quotes, i.e. type="10"
.
But the $atts
in your shortcode function is not defined before the shortcode_atts()
is called, so the function should be defined as follows:
function diwp_create_shortcode_arts_post_type( $atts )
And because the function is already parsing the parameters which are stored in the $atts
array, then you just need to use the parameters in your tax_query
(i.e. taxonomy query) clause:
'tax_query' => array(
array(
'taxonomy' => 'Types',
'field' => 'term_id',
'terms' => wp_parse_id_list( $atts['type'] ),
),
),
Note: In the above example, I used wp_parse_id_list()
so that we can pass a list of term IDs, e.g. [arts-list type="10,11,12"]
. But more importantly, make sure the IDs point to valid terms in the Types
taxonomy.