Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › I want to use post_id in Advanced Description field
- This topic has 10 replies, 2 voices, and was last updated 6 years, 2 months ago by
Ernest Marcinko.
-
AuthorPosts
-
March 10, 2020 at 5:26 pm #26195
awaistufail02
ParticipantI 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 #26196awaistufail02
Participantoops! 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 #26203Ernest Marcinko
KeymasterHi!
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!
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; }March 11, 2020 at 11:31 am #26209awaistufail02
ParticipantI 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 #26211Ernest Marcinko
KeymasterI 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.
March 11, 2020 at 3:34 pm #26217awaistufail02
ParticipantYes! you were right I was doing something wrong. It is now working.
Thank you!
March 11, 2020 at 3:43 pm #26219awaistufail02
ParticipantWait..!
I want to ask one more thing…
|post_id| is not working in titlefield.
What’s wrong?March 11, 2020 at 3:56 pm #26220awaistufail02
Participantby title field I mean the Advanced Title Field
March 11, 2020 at 3:59 pm #26221Ernest Marcinko
KeymasterIt’s because the code only applies on the content. Change that to this, it will work on the title as well:
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; }March 11, 2020 at 4:04 pm #26224awaistufail02
ParticipantThank you so much!
I have already rated five stars to your plugin.March 11, 2020 at 4:05 pm #26226Ernest Marcinko
KeymasterYou are very welcome, and thank you for that 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.