Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › I want to use post_id in Advanced Description field
This topic contains 10 replies, has 2 voices, and was last updated by Ernest Marcinko 3 years, 3 months ago.
- AuthorPosts
- March 10, 2020 at 5:26 pm #26195
I want to compare different products on a compare-products page. For searching and adding products in compare list I’m using Ajax Search Pro and in order to add products in compare list I want Advanced Description Field to be like this:
Everything else is working just fine but I’m not able to get the post_id of the product being displayed in search list. Need your help.
March 10, 2020 at 5:34 pm #26196oops! I should have put it in CODE
<a href="http://pkmobilereviews.com/compare/?post_id={post_id}"> {__image} {titlefield} </a>
March 11, 2020 at 10:07 am #26203Hi!
The post ID is not available via those fields unfortunately, but it should be doable via a simple custom code. First, change the advanced content field to this:
<a href="http://pkmobilereviews.com/compare/?post_id=|post_id|"> {__image} {titlefield} </a>
Then, try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
Best,add_filter( 'asp_results', 'asp_change_content_post_id', 10, 4 ); function asp_change_content_post_id($results, $search_id, $is_ajax, $args) { foreach ( $results as $k => &$r ) { $r->content = str_replace('|post_id|', $r->id, $r->content); } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 11, 2020 at 11:31 am #26209I have tried it but it is not returning me the numeric post id. Instead it is returning the me this in url
https://pkmobilereviews.com/compare/?post_id=|post_id|
Any other solution?
March 11, 2020 at 2:17 pm #26211I am almost positive that this should work with the custom code. Make sure that the custom code is placed in the correct file. If you want, you can add temporary FTP details, and I can do it for you.
There is no better solution I’m afraid.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 11, 2020 at 3:34 pm #26217Yes! you were right I was doing something wrong. It is now working.
Thank you!
March 11, 2020 at 3:43 pm #26219Wait..!
I want to ask one more thing…
|post_id| is not working in titlefield.
What’s wrong?March 11, 2020 at 3:56 pm #26220by title field I mean the Advanced Title Field
March 11, 2020 at 3:59 pm #26221It’s because the code only applies on the content. Change that to this, it will work on the title as well:
Best,add_filter( 'asp_results', 'asp_change_content_post_id', 10, 4 ); function asp_change_content_post_id($results, $search_id, $is_ajax, $args) { foreach ( $results as $k => &$r ) { $r->content = str_replace('|post_id|', $r->id, $r->content); $r->title = str_replace('|post_id|', $r->id, $r->title); } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 11, 2020 at 4:04 pm #26224Thank you so much!
I have already rated five stars to your plugin.March 11, 2020 at 4:05 pm #26226You are very welcome, and thank you for that 🙂
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.