I am trying to get the variable passed in my shortcode so I can do a request with the id to a API.
The shortcode looks like this: [product id="2"]
In my function I want to do something with the "2".
Code so far:
function getSingleProduct( $attr ) {
shortcode_atts( [
'id' => '0',
], $attr );
// Do someting with the "2".
do_request( 'GET', get_api_url() . 'api/product/' . "2" ); // This "2" comes from the shortcode
}
add_shortcode( 'product', 'getSingleProduct' );
// Do something with the "2"
, just do something with it, I think I don't understand your question. Can you try to explain the problem deeply?shortcode_atts();
I am totally new to this.[product id="3"]
the 2 needs to be a "3". And the request will go according to the param in the sortcode.