0

I want to automatically get products from woocommerce for a chosen brand, inside a brand's listing on a other part of the site using Sabai Directory.

this

<?php Sabai::_h($entity->getSlug());?>

stamp listing slug on the page

The plugin shortcode pick a list of product of a chosen brand

[shortcode_products_by_brand title="Sample brand products" per_page="12" columns="4" orderby="title" order="desc" brand="brand_slug" operator="IN"]

listing_slug equals to brand_slug so i tried with this

<?php echo do_shortcode('[shortcode_products_by_brand title="Sample brand products" per_page="12" columns="4" orderby="title" order="desc" brand="'. Sabai::_h($entity->getSlug()) .'" operator="IN"]') ?>

Obviously, it does not work :D May I ask your help? Thank you for your time, and sorry for my poor english and php skills :)

  • 1
    The problem is almost certainly with how the Sabai::_h() method operates, which (unless you wrote the class) is going to be off topic. – s_ha_dum May 11 '15 at 21:10
0

this should work

<?php echo do_shortcode('[shortcode_products_by_brand title="Promozioni" per_page="12" columns="4" orderby="title" order="desc" brand="'. $entity->getSlug() .'" operator="IN"]') ?>
  • Could you expand on why this would work and how this solves OPs issue? – Howdy_McGee May 14 '15 at 21:56
  • it really works – lexofran May 19 '15 at 11:27
  • i had a talk with the creator of sabai directory. He wrote:"Sabai::_h() is the same as doing echo() and htmlspecialchars() at the same time. If you simply need to get the slug, you can just use $entity->getSlug()." – flepso May 19 '15 at 13:05
0

I am not sure what are you trying to get here: Sabai::_h($entity->getSlug());

but Since you are echoing a statement, you need to store the value in a variable first and then call it within the shortcode string.

<?php $brand_variable = Sabai::_h($entity->getSlug());
    echo do_shortcode('[shortcode_products_by_brand title="Sample brand products" per_page="12" columns="4" orderby="title" order="desc" brand="'. $brand_variable .'" operator="IN"]') ?>
  • If that object method returns a string the solution you propose is functionally equivalent to what the OP is already trying to do. It is not necessary to save the value to a variable first. – s_ha_dum May 11 '15 at 19:58
  • Sabai::_h($entity->getSlug()); this one stamp on the screen the post slug of the directory plugin – lexofran May 11 '15 at 20:02
  • Did you try it my way? – Wali Hassan May 11 '15 at 20:03
  • @WaliHassan: your way doesn't make sense. Try echo 'this is '.get_the_title(); vs. $title = get_the_title(); echo 'this is '.$title;. This is basic PHP. – s_ha_dum May 11 '15 at 20:13
  • Right ... You got it :) – Wali Hassan May 11 '15 at 21:53
0

First: I feel the need to ask where exactly are you putting this php code? Hopefully not in the content area of the page through the WordPress Dashboard as php does not work there. (This is the "is it plugged in?" question that needs to be asked first.) You must put all php code inside a .php file in your theme somewhere. Don't feel insulted or stupid, it happens to all of us once, I just have to ask. Moving on:

Clearly the problem lies with the use of Sabai::_h($entity->getSlug()) as it is (almost) the only change.

My first instinct when encountering a function that I do not know exactly what its output will be is to use var_dump() and take a good look at the output. Hopefully you have a construction area, if not you can see this question here to make one on your current site How can I execute some small piece of PHP code in a sandbox area of my WP?.

Try doing a var_dump(Sabai::_h($entity->getSlug())) and se if the output is what you expect it to be.

You might also try

<?php echo(do_shortcode('[shortcode_products_by_brand title="Sample brand products" per_page="12" columns="4" orderby="title" order="desc" brand="brand_slug" operator="IN"]')); ?>

The purpose of this is simply to attempt to isolate the problem one step at a time in the event that the var_dump() didn't illuminate anything. *I also added parenthesis to the echo statement; I know it isn't required, but that's the way I like to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.