Home › Forums › Pro Support › Custom URL
- This topic has 24 replies, 3 voices, and was last updated 2 years, 11 months ago by
Tom.
-
AuthorPosts
-
August 17, 2020 at 6:23 am #18361
Samuel
ParticipantHi,
I already post my question on the Generate Press forum but maybe better if I’m asking here :
Basically I want to redirect to a custom URL. Custom URL that would be calling from a custom field present in each post.
In each post I have a custom field, name is “url-booking” and value is the custom URL. I think the call would be something like
get_field($url-booking);
but I really don’t know how to configure it with WPSP.Hope this is clear enough,
Thanks a lot,
SamuelAugust 17, 2020 at 7:06 am #18363Samuel
ParticipantHi again,
I just wanted to add that I would need this only for custom post types called “hotel”.
I really don’t speak the php and it’s frustrating because I know it would something like “if post is hotel then link to custom url”
I saw a reply you made regarding a similar request for gallery
So would it be something like this possible ?
add_filter( 'wpsp_post_href', function( $href ) { if ( 'hotel' == get_post_type() ) { return get_field($url-booking); } return $href; } );
August 17, 2020 at 2:08 pm #18374Tom
KeymasterHi there,
As of right now, no filter exists there.
I agree that it would be a good filter to have – I’ve made a note of this for the next version.
August 18, 2020 at 12:43 am #18378Samuel
ParticipantThanks for your reply Tom,
Just to know what’s the next step for me, do you have any idea about when a new version would be released ?
August 18, 2020 at 1:09 pm #18391Tom
KeymasterWe had a meeting about this yesterday. We’ll be trying to get an update out for free and pro within a month.
August 20, 2020 at 8:17 am #18432Samuel
ParticipantThanks a lot
August 20, 2020 at 2:56 pm #18439Tom
KeymasterNo problem 🙂
September 10, 2020 at 1:43 am #19164Samuel
ParticipantHi Tom,
Can you confirm me you’re adding this filter we were talking about in the next update coming ?
Thanks a lot
September 10, 2020 at 9:42 am #19185Tom
KeymasterHi there,
Yes, you can see it here in 1.2: https://github.com/tomusborne/wp-show-posts/blob/release/1.2/wp-show-posts.php#L460
We’ll be entering alpha testing soon 🙂
September 12, 2020 at 2:12 am #19241Samuel
ParticipantGreat news ! Thanks Tom
September 12, 2020 at 1:19 pm #19247Tom
KeymasterNo problem! 🙂
October 3, 2020 at 3:13 am #20603Samuel
ParticipantHi Tom,
Coming back to do some tests with your Alpha 1.2 version.
Could you help me understand how to implement the “get custom url” function we were talking about ?
To remind you what I’m trying to do is :
I have hotel pages where I use a custom field I called “url-booking” and where I put an URL.
I need WP Show Post to link to this “url-booking” custom URLHere is a example of what I’m doing right now using another (but heavy) plugin : https://monvoyageencolombie.com/ou-loger-region-caraibe/
Thanks for your help,
SamuelOctober 3, 2020 at 1:47 pm #20615Tom
KeymasterHi there,
You can do this:
add_filter( 'wpsp_title_href', function( $href ) { $custom_url = get_post_meta( get_the_ID(), 'url-booking', true ); if ( $custom_url ) { return $custom_url; } return $href; } );
Hope this helps!
October 4, 2020 at 8:43 am #20651Samuel
ParticipantHi Tom,
The function is working well but partially, Title’s link is redirecting to the custom URL fine, but Image and Button’s link are redirecting to the original page…
Is this possible to make all links to redirect to custom URL ?
Thanks for your help,
SamOctober 5, 2020 at 3:28 pm #20708Tom
KeymasterFor the image, you can duplicate the function but use
wpsp_image_href
as the filter name.For the button, try this:
add_filter( 'wpsp_read_more_output', function( $output, $settings ) { $custom_url = get_post_meta( get_the_ID(), 'url-booking', true ); if ( $custom_url ) { return sprintf( '<div class="wpsp-read-more"><a title="%1$s" class="%4$s" href="%2$s">%3$s</a></div>', the_title_attribute( 'echo=0' ), esc_url( $custom_url ), $settings['read_more_text'], esc_attr( $settings['read_more_class'] ) ); } return $output; }, 10, 2 );
-
AuthorPosts
- You must be logged in to reply to this topic.