Problem: I would like to redirect posts in a specific post type to a URL saved in a custom field on each post.
Solution: Unfortunately Toolset isn't set up to handle redirects so this will require custom code. Here is an example:
function my_cpt_template_redirect() { if( get_post_type() == 'your-cpt-slug' ) { $id = get_the_id(); $url = get_post_meta( $id, 'wpcf-' . 'your-field-slug', true ); if( $url ) { wp_redirect( $url ); die; } } } add_action( 'template_redirect', 'my_cpt_template_redirect' );
Replace your-cpt-slug with the slug of the post type where you want to apply these redirects. Replace your-field-slug with the slug of the URL field. Additional changes may be necessary based on your requirements.
Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
https://developer.wordpress.org/reference/functions/get_post_meta/
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 1 month ago.
Assisted by: Christian Cox.