Executing shortcodes in Advanced Title Field & Advanced Description Field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Executing shortcodes in Advanced Title Field & Advanced Description Field

This topic contains 2 replies, has 2 voices, and was last updated by NaturesLens NaturesLens 6 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #16367
    NaturesLens
    NaturesLens
    Participant

    Basically – as above – how would I go about this – I have nice nice codes on my events, for formatting the schedule nicely (start date to end date, etc), if I pull out {_EventStartDate} directly, I get it all unformatted – same for location – but shortcodes do not seem to execute within the Advanced Title & Advanced Description Fields areas

    Is there a way to have these working – and hence for the shortcode to pick up on the post-id – or it could be passed in

    #16395
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    The advanced title and content fields cannot handle shortcodes, only custom field based content. It’s because is is executed after the content filter is used.

    The only way to add shortcodes there is via custom code, like so:

    It may not work though, if the shortcode is registered later during the execution flow. Also, the $r->id variable contains the post ID, if that is needed.
    In that case line 12 would look simething like this:

    $r->content = do_shortcode('[SOME_SHORTCODE id='.$r->id.']') . $r->content;

    I hope this helps!

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #16414
    NaturesLens
    NaturesLens
    Participant

    Superb – thanks – that made it a lot easier – my shortcodes can be called as functions as well – so – I came up with this:

    add_filter(‘asp_results’, ‘asp_add_event_details_to_search_content’, 10, 1);

    function asp_add_event_details_to_search_content($results)
    {
    foreach($results as $k => & $r)
    {
    $append = ”;

    if ($r->content_type != “pagepost”) continue;

    $cost = tec_cost($r->id);
    $location = tec_full_location($r->id);
    $duration = tec_formatted_schedule($r->id);

    if ($cost !== ”)
    {
    $append = $append . $cost;

    if ($location !== ”)
    {
    $append = $append . ‘ – ‘;
    }
    }

    if ($location !== ”)
    {
    $append = $append . $location;

    if ($duration !== ”)
    {
    $append = $append . ‘ – ‘;
    }
    }

    if ($duration !== ”)
    {
    $append = $append . $duration;
    }

    if ($append !== ”)
    {
    $append = ‘<div class=”additional_search_meta”>’ . $append . ‘</div>’;
    }

    $r->content = $r->content . $append;
    }

    return $results;
    }

    And that results in the results looking like the attached

    Attachments:
    You must be logged in to view attached files.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.