I am new to WP, and stuck in a shortcode. here’s my issue. created a shortcode like this
add_shortcode( 'position', 'object_position_in_post');
function object_position_in_post( $atts = [] ) {
$atts = array_change_key_case( (array) $atts, CASE_LOWER );
$format = $atts['format'];
$position = get_post_meta( $product, '_target_position'.$post->ID, true);
if(isset($atts['format']) && !empty($atts['format'])){
if($format === 'num')
return $position;
if($format === 'word')
$formatter = new NumberFormatter('en_US', NumberFormatter::SPELLOUT);
return str_replace('-', ' ', $formatter->format($position));
}
return &position;
}
I need to use it on posts where multiple products are called in blocks using a loop; so how can I pass addition params so that it becomes dynamic and works flawlessly. shortcode should become something like this
[position format='what-was-passed' product_id='".$product->ID."' postid='".$post->ID."']
Any help is highly appreciated;
Desc:
I have custom posts where I have pulled wooproducts based on some logic to list them as per their ‘ranks’, and that list is being generated via loop (including product short description), I have also saved those ranks as post meta to concerned products in connection with the custom post id. Now I am pulling those product specific meta data via this shortcode which is placed inside short description of the products.
Ref. page https://www.zotezo.com/in/top/best-flaxseed-oil-supplements-in-india/