Custom Shortcode In Results Layout Not Working

Home Forums Store Locator Plus Custom Shortcode In Results Layout Not Working

This topic contains 3 replies, has 2 voices, and was last updated by  Cici 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #43847

    Zachary
    Participant

    I’m trying to call a custom shortcode from within the Results Layout editor, but I’m running into an issue where SLP shortcodes are not resolving correctly.  My custom shortcode lives within my theme’s functions.php file.

    Here’s an example of code that’s not working for me:

    function my_shortcode_function() {
    $string = “”;
    $string = do_shortcode(‘[[slp_location data.sl_pages_url]]’);
    $string = substr($string, 4);
    return $string;
    }
    add_shortcode( ‘my_shortcode’, ‘my_shortcode_function’ );

    I’ve added [[my_shortcode]] to the Results Layout editor.  The above code returns ‘_location data.sl_pages_url]’, which looks like the do_shortcode() function is not resolving before the substr() runs. If I remove my substr() function, it correctly returns a string (in this example, a store page URL for a location, such as, http://quala.us.com/locations/saginaw-tx/).

    Am I missing something here? Or is this simply not allowed?

    Ultimately what I’m trying to do is for each location, get the related store page categories for that related store page, as we are trying to display some of them on the front-end of the site. I have found a temporary workaround using an AJAX call to the WP API, but I’d rather do so using PHP server-side.

    Any help or direction here would be very helpful. Thanks!

    Attachments:
    You must be logged in to view attached files.
    #43854

    Cici
    Keymaster

    You cannot use PHP code in the layouts.   WordPress shortcode processing does not work that way

    #43861

    Zachary
    Participant

    Is there an SLP location shortcode I can use to get the data I need? (Location –> Store Page –> Store Page Categories)?

    Or is there a way to not use the built-in Results Layout, and instead create my own template and tell SLP to use it, so that I can run custom PHP code?

     

    #43862

    Cici
    Keymaster

    I believe you can do what you would like with the Power Add-on and you might need to update your Enhanced and Widgets to Experience add-on. Both are at 4.6.4. Since you have older versions of the Enhanced Add-ons and Pages add-ons you could request a coupon for a discount, but with the caveat that you update WP. I am not trying to upsell you but I cannot advise with older versions of add-ons and WP. We are always moving forward with improvements and efficiency with updates tested against the NEXT WP development (currently our dev team is already working towards the WP 4.7 release pending for Dec.)

    Unfortunately the issue you will have is that you are running an outdated version of WordPress. The Power and Experience add-on needs WP 4.4 or above. There were important security updates and you are quite a bit behind. Your theme must also be using jquery 1.12 or above when you update WP.

    Here is a tit for tat relationship between the Legacy add-ons and newer add-ons that would allow you to achieve your results without having to write all the extra code. (as long as your theme does not interfere with the SLP plug-in)
    Power includes the Pages,Tagalong,ProPack,Contact Extender, and Directory Builder add-ons, the updated versions of those add-ons. See the docs about the Pages and Category taxonomy relationship

    Page Templates MUST follow the WordPress dichotomy. That was changed back in WP 4.3.2

    See Page template info here and more in new docs site.Power documentation

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.