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 5 years, 4 months ago.
- AuthorPosts
- January 18, 2018 at 11:41 am #16367
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
January 19, 2018 at 10:35 am #16395Hi,
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 :)
January 19, 2018 at 4:52 pm #16414Superb – 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. - AuthorPosts
You must be logged in to reply to this topic.