Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Use ACF as permalink for result tile link
This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko 2 years, 5 months ago.
- AuthorPosts
- January 6, 2021 at 8:39 pm #31040
Is it possible to create an ACF to use as the permalink for a result tile, but still show the title, excerpt, button, etc.. on the tile? I saw this for the lite version https://wordpress.org/support/topic/using-acf-value-instead-of-permalink/ , but does it change the permalinks for all the results or just the ones were that ACF is filled out?
https://resources-marqeta-ms.pantheonsite.io/resources/
https://resources-marqeta-ms.pantheonsite.io/wp-admin/post.php?post=7423&action=edit
https://resources-marqeta-ms.pantheonsite.io/wp-admin/edit.php?post_type=resources-home
https://resources-marqeta-ms.pantheonsite.io/wp-admin/admin.php?page=asp_settings&asp_sid=2January 6, 2021 at 9:17 pm #31041I just edited the ASL code for ASP and it seems to work
add_filter( 'asp_results', 'asp_custom_link_meta_results', 10, 1 ); function asp_custom_link_meta_results( $results ) { // Change this variable to whatever meta key you are using $key = 'url_to_asset'; // Parse through each result item foreach ($results as $k=>$v) { if ( function_exists('get_field') ) $new_url = get_field( $key, $v->id, true ); // ACF support else $new_url = get_post_meta( $v->id, $key, true ); // Change only, if the meta is specified if ( !empty($new_url) ) { $results[$k]->link = $new_url; } } return $results; }
Unless there is an updated snippet for ASP?
January 6, 2021 at 10:49 pm #31042Is it possible to have the ‘url_to_asset’ to open in a new tab?
January 7, 2021 at 11:43 am #31046That code looks perfectly fine to me, great job!
Well, you can configure the plugin to open all links in a new tab here: https://i.imgur.com/4ae6SNo.png
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
January 7, 2021 at 8:35 pm #31049I only need it to open a new tab for the ones that have text in the ACF. If you have a quick way to do that, that would be great. If not I will figure it out with some more PHP.
January 8, 2021 at 1:33 pm #31051Well, for that I recommend the results templating, using a hook is not going to work with this in my opinion.
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.