Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Custom Function to redirect singular post if specific meta field is empty

Technically, this code looks like it is accomplishing what you are trying to do, and I don’t see any glaring holes.

But, do you really intend on redirecting people away from your site when they just clicked to view someone’s bio? That sounds very confusing to the user and would result in a poor user experience, I think.

Regarding security, who is entering the data into the ecpt_website field? You or users? If users, I would definitely avoid that.

I assume these are offsite links, but if you are using internal links, you should use wp_safe_redirect() instead which is meant for internal linking.

Related Posts:

  1. Detect meta value changes when post is updated (post_updated)
  2. Search everything (posts, pages, tags, cpt, meta)
  3. Custom Taxonomy Permalinks Redirection
  4. get_post_meta not working on publishing
  5. Redirect 404 page with ID in slug to associated page with same ID in slug
  6. Create short URL with auto 301 redirect
  7. redirect after submiting post for review
  8. Custom attachment function not working in v5.4.2?
  9. Stored meta from attachment, video length?
  10. Rich Custom Field for Custom Post type not saving
  11. Post AND page parameter for WP function
  12. Insert Multiple Post with Same Publish Button
  13. wp_insert_post generates endless posts
  14. Remove standard meta boxes from custom taxonomy
  15. Update CPT post meta with update_post_meta and cron job
  16. Custom meta box data array: foreach not working correctly?
  17. Undefined Variable – Custom Post Type Meta
  18. What’s the difference between same wp functions get_posts(); functions in different form?
  19. I did group my search results by post type, but how can i give each of them its own order?
  20. Ordering posts in Search & taxonomy by post_meta
  21. Dequeue scripts and styles only for specific custom post type
  22. Insert post metadata for all posts in CPT at once if metadata no existent
  23. Function to display custom post type on front page makes menu items dissapear
  24. Display custom post type from dynamic custom field
  25. custom post type not showing in menu
  26. Show the same Article Available in Other Categories
  27. how to delete all users and posts based on ‘user_meta’?
  28. Show category ID on custom post type
  29. Custom post type redirected to homepage – how to debug
  30. Populate dropdown from one custom post type inside another custom post type
  31. Meta Key Value in current-user-only loop
  32. How to customize a permalink (URL) structure?
  33. How to check if user meta field is empty in conditional else statement
  34. Custom Post Type with Templates using Meta Boxes?
  35. How to set YouTube video as featured image?
  36. Notice: Undefined index: error and understanding wordpress
  37. Can I list a custom post type within another custom post type in the admin area?
  38. Change custom post type slug from plugin options
  39. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  40. Get posts between custom dates
  41. How to implement a Google map store locator
  42. 301 redirect for converted post type
  43. Can’t edit custom post type
  44. redirecting improperly after updating custom taxonomy term when referring from CPT edit page
  45. Deleting Custom Posts & Meta Data on Uninstall
  46. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  47. Post image in WordPress not appearing on home page
  48. How do I create an archive page as a including metadata?
  49. Set URL link to featured image of custom post type
  50. Child post with numeric only slug keeps redirecting to parent
  51. Change CPT archive title
  52. AJAX load more for different custom post type loops
  53. PHP variable not regenerating when publishing multiple posts at the same time
  54. changing meta value and meta key of price field
  55. Posting to a Custom Post Type from front end – user generated content
  56. On update or create post redirect to current post position in list
  57. I need to add endpoint for wordpress categories
  58. Update Post Meta for a logged in user
  59. Getting meta in editor plugin, and event triggering issue
  60. How to duplicate entire custom post type
  61. A better way to add a meta box to custom post types
  62. Restrict Access to Posts based on Custom User and Post Meta Data
  63. How to target a specific custom post type post and its all children and grandchildren?
  64. Featured image overlay when changing post status
  65. Two Custom Post Types Many to Many Relationship
  66. Should wp_postmeta meta_key always be unique for a given post_id?
  67. WordPress wrapped added a span tag to every single p tag
  68. ACF field key/value to show on taxonomy list
  69. Re-registering a custom post type not working (not showing up)
  70. Display featured image from one CPT within another CPT query
  71. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  72. get_post_meta returning no value in custom post type alert email
  73. Query taxonomy of taxonomy of custom post type
  74. Best way to style first post differently?
  75. How to make custom posts types display when published for the future
  76. redirect automatic page that serves custom posttype content
  77. post meta parameter in post custom-post-type endpoint with restapi
  78. How do I set all of a particular post meta to a value within the custom post type I’m in?
  79. How to rewrite url for any specific taxonomy?
  80. create a new page from a custom post type similar to an authors page
  81. CPT archive admin menu label
  82. Anon function and add_meta_box
  83. Update postmeta Parent when post_status child change
  84. Metabox not show in categories custom post type cmb2
  85. WordPress request fiter order by related post’s post_title
  86. Redirect custom post type category to other custom post type category
  87. Hide a widget inside a div on specific type of post
  88. Shortcode not working with post counter
  89. Changing default ‘posts’ parameters with register_post_type_args
  90. Update database from Quick Edit according to Checkbox state of Custom Post Type
  91. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  92. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  93. Dynamic Custom Fields
  94. Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
  95. Show Custom Post Type meta boxes only on Page Edit
  96. Cannot save CPT meta box
  97. Allow users to create posts without logging in?
  98. How to change permalink to include custom post type
  99. Custom filter function not working with Custom post type
  100. Configuring a meta query with multiple post types that have the same relationship on a single page
Categories custom-post-types Tags custom-post-types, functions, post-meta, redirect
How to upload PDF from Front-End and post automatically?
Using wordpress functions in class and change my code to OOP PHP

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress