Skip to content

Instantly share code, notes, and snippets.

@MLnick
Last active August 29, 2015 14:16
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 MLnick/a70f5cc137538f63eb3b to your computer and use it in GitHub Desktop.
Save MLnick/a70f5cc137538f63eb3b to your computer and use it in GitHub Desktop.
Custom Graphflow Shortcode using Code Snippets Plugin
add_shortcode('graphflow_shortcode_demo', 'graphflow_shortcode_demo_display');
function graphflow_shortcode_demo_display($attr) {
ob_start();
if ( isset( $_REQUEST['cat'] ) ) {
$cat_id = $_REQUEST['cat'];
$term = get_term_by( 'id', $cat_id, 'product_cat', 'ARRAY_A' );
$cat_name = $term['name'];
echo do_shortcode( '[graphflow_recommendations title="Recommended for you in ' . $cat_name . '" columns=4 per_page=4 product_cat=' . $cat_id . ']' );
} else {
echo do_shortcode( '[graphflow_recommendations columns=4 per_page=4]' );
}
echo '<form id="category-select" class="category-select" action="' . esc_url( home_url( '/' ) ) . '" method="get">';
wp_dropdown_categories( array( 'taxonomy' => 'product_cat' ) );
echo '<input type="submit" name="submit" value="Get Recommendations in Category"/><input type="hidden" name="page_id" value="6774" /></form>';
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment