Support » Plugin: WP Shopify » Show Products by Tag

  • Resolved lakewebworks


    Hi Fahad,

    Is it possible to use your plugin to display a set of products from Shopify filtered by tag? If so, can you provide an example of what the shortcode would look like?

    I tried [wp-shopify-product tag="mytag"] but it didn’t work.


Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Fahad Mahmood


    Initially when i developed this plugin so this attribute was not added, i need to review their API again to add this as a new feature. Can you please wait a little so i can check the possibility? I appreciate that you brought it to my attention.

    That sounds good, thanks. What I’m hoping to do is to display a list of a set of products (so probably this would be a modification of your [wp-shopify] shortcode because it’s a set of products), filtered by tag (so maybe there could be a second attribute to limit the number of products displayed). Thanks for the support!

    Plugin Author Fahad Mahmood


    I understand your requirements, hopefully soon you will get an update. Your patience is appreciated.

    Hi Fahad,

    I wanted to follow up to let you know that I looked at the Shopify API and got what I think is a better idea. Since the API supports filtering a product list by collection:

    GET /admin/api/2019-10/products.json?collection_id=841564295

    …I thought it might be worth trying to use your shortcode to pull in a particular collection. That way the content of the set of products could be managed on the Shopify end (i.e., one could create a SMART collection based on a tag, or many other ways).

    I experimented by modifying your functions.php file. For the wpsy_shop_display_shortcode function I modified the request URL to

    /admin/products.json?collection_id=[my collection id number]

    …and it worked fine. So I think if your plugin was extended with a shortcode option that lets one specify a collection number, and a number to limit the number of results, that would work.


    Hi Fahad,

    I’ve never worked with WordPress shortcodes or the Shopify API code before, but I was able to successfully modify your functions.php file to get what I needed. I’m sure you can improve it and extend it to make your plugin better, but this got the job done for me:

    function wpsy_shop_display_shortcode($atts = array(), $content = null, $tag = ''){
    		// normalize attribute keys, lowercase
    		$atts = array_change_key_case((array)$atts, CASE_LOWER);
    		$collection_id = ($atts['collection_id']?$atts['collection_id']:$_GET['collection_id']);
    		$limit = ($atts['limit']?$atts['limit']:$_GET['limit']);
    		$wpsy_db_data = get_option('wpsy_db_data');
    		$url = $wpsy_db_data['wpsy_url'];
    		$api_key = $wpsy_db_data['wpsy_api_key'];
    		$password = $wpsy_db_data['wpsy_password'];
    	   //API URL to get product by ID
    		$requestURL = "https://" . $api_key . ":" . $password . "@" . $url;
    		$requestURL .= '/admin/products.json?collection_id=' . $collection_id;
    		$response = wp_remote_get($requestURL, array(
    		  'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
    		  'body' => null,
    	   if (is_wp_error($response)) {
    		  $o = wpsy_shop_product_display_get_error(__('Sorry, the site is having a technical difficulty.','wp-shopify').':'  . $response->get_error_message());
    		  return $o;
    	   }  else if (wp_remote_retrieve_response_code( $response ) != 200) {
    		  $o = wpsy_shop_product_display_get_error(__('Sorry, did not get what we expected from the shop.','wp-shopify').':'  . wp_remote_retrieve_response_message( $response )); 
    		  return $o;
    	   $response = json_decode(wp_remote_retrieve_body($response));	
    	   if(!empty($response) && isset($response->products)){
    	<ul class="wp_shopify">
    	       $Count = 0;
    		   foreach($response->products as $product_data){
    			$product_data->price = wpsy_product_price($product_data);
    			$product_url = home_url().'/product/?id='.$product_data->id;
    	<a title="<?php echo ucwords($product_data->product_type); ?>" href="<?php echo $product_url; ?>"><img alt="<?php echo $product_data->title; ?>" src="<?php echo $product_data->image->src; ?>" /></a>
    	<a class="ptitle" href="<?php echo $product_url; ?>"><?php echo $product_data->title; ?></a>
    	<strong><?php echo $product_data->price; ?></strong>
    			if ($Count == $limit){
    				break; //stop foreach loop after limit is reached
    	<p style="clear:both;">The response: <?php //var_dump($response); ?></p>
    	<p>The limit: <?php echo $limit; ?></p>
    		$o = ob_get_contents();
    	   return $o;

    There aren’t that many Shopify-WordPress plugins out there, and this did exactly what I wanted (as opposed to the other WPShopify plugin that creates its own cart on the WordPress side and doesn’t let you link over to the product page on your Shopify site). So I think your plugin fills a valuable niche and will be successful if you develop it further. Thanks for your work, it really helped me out… Hope my little modification helps you in turn!

    Oh, I should add that my shortcode looked like this:

    [wp-shopify collection_id="141421936749" limit="4"]

    Plugin Author Fahad Mahmood


    Thank you, i will check it and will add it to the plugin files carefully.

    Plugin Author Fahad Mahmood


    I have just released it with an improved version of shortcode with these two new attributes

    [wp-shopify collection_id=”141421936749″ limit=”4″]

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.