Skip to content

Instantly share code, notes, and snippets.

@ianhoyte
Created February 4, 2020 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianhoyte/51817ce88d71b4a5b3e824503ef13aec to your computer and use it in GitHub Desktop.
Save ianhoyte/51817ce88d71b4a5b3e824503ef13aec to your computer and use it in GitHub Desktop.
Shortcode within a shortcode
/**
* wps_nested_shortcodes_products_display
*
* Place this in functions.php
*/
function wps_nested_shortcodes_products_display( $atts ) {
$a = shortcode_atts( array(
'types_shortcode' => '',
'show_featured_only' => '',
'excludes' => '',
'hide_quantity' => '',
'page_size' => '',
), $atts );
/**
* Retrieve the value from your "types" shortcode (types_shortcode attribute)
*/
$field = do_shortcode('[types field="' . $a['types_shortcode'] . '"][/types]');
// build the shortcode with the desired options
$wps_products = do_shortcode('[wps_products product_id="' . $field . '" show_featured_only="' . $a['show_featured_only'] . '" excludes="' . $a['excludes'] . '" hide_quantity="' . $a['hide_quantity'] . '" page_size="' . $a['page_size'] . '"]');
return $wps_products;
}
add_shortcode( 'wps_dynamic_products_id', 'wps_nested_shortcodes_products_display' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment