remove the else after the foreach:
add_action('parse_request', 'fid_parse_request');
function fid_parse_request($wp) {
// only process requests with "fid"
if (array_key_exists('fid', $wp->query_vars) && $wp->query_vars['fid'] != '') {
$args = array('post_type' => 'faculty_profile', 'meta_key' => 'wid', 'meta_value' => $wp->query_vars['fid'] , 'numberposts' => 1);
$redirect_to_post = get_posts($args);
if (!empty($redirect_to_post ) ) {
foreach ($redirect_to_post as $p) {
$link = get_permalink($p->ID);
wp_redirect( $link , 301 );
exit;
}
}
$url="http://cnn.com/";
wp_redirect( $url , 404 );
exit;
}else{
return $wp;
}
}
Related Posts:
- How do I Redirect a WordPress Page?
- How to disable Uncategorized category URL?
- Display most recent post in category instead of archive?
- How to after saving or publishing a post redirect back to the original page
- Phantom 302 status code when sending a POST requests on pages
- Redirect before post page
- Posts are being redirected to xampp home page
- Why is WordPress redirecting users to random posts after commenting?
- Plain permalinks not working!
- Relative redirects for posts, categories, products and product categories
- 301 (static page instead latest posts)
- Set static page/post from another blog on same network
- redirect to uploaded (wordpress) post after form submission from front-end
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- WordPress 302 Redirect to Random Product/Post/Page
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- add_rewrite_rule and template redirect not working
- Creating a redirect option for current page url
- How Do I Redirect WordPress Pages but not posts?
- Every time I try accessing a post it redirects me to the feed
- Redirect old Posts URL to new URL
- Redirect to custom post if custom archive page has just one result?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Submit New Post
- How to redirect if is post edit or publish page?
- how to redirect page after delete post inside a post page?
- issue in wordpress auto delete post and redirect to another 1
- Redirect posts to sub domain except pages
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- Post pages are redirecting to the 404 page in wordpress
- Permalink issue with new blog posts > getting 301 redirect
- Redirection – bulk edit 404s to new tomain
- Filter post by users creation date
- How to draft posts after being published with x days
- How do I change the template specifically for single posts?
- Change Old WordPress Post Date Year
- How to set a Post’s default visibility to ‘Private’ in Gutenberg?
- wp-insert-post execute from server?
- Sticky Post Doesn’t always work
- WordPress doesn’t save or publish new posts
- Check if almost 10 year old – working code is up to date
- How can I pass form entry to another form on a new page
- Yoast breadcrumb URL shows category instead of the page
- Post Image Gallery After Content Function messes with other content
- Embedding Post Editor Into External Site
- Keep the old referrer after failed login
- Add data attribute of post_id for Internal links
- Single Post Gallery Using Shortcode
- Please help a newbie with blog page issue?
- How do I assign an attachment to a post using only the REST API?
- How to insert custom text after H1 to all my blog posts?
- Posting an article containing mathematical symbols and R code
- How to create loop of posts except post ID defined via ACF field
- Menu Items disappearing/being empty on save or post edit
- Alt text attributes not showing over portfolio images
- Show single post child category from a determined parent
- Author post count in category
- How to remove redirection
- How to work with posts and sub posts?
- wordpress admin missing Posts button
- How to show posts in grid style on search result page?
- My website is showing today’s date instead of published date since db migration to a new wordpress
- How can I change the date format of the revision list?
- Single Post function to display all single post images in a carousel
- Set post title font size automatically according to number of words in post title
- Get post slug and match with menu item slug to change css
- Implementing a multilingual WordPress site by installing several instances of WordPress and redirecting
- Run a function when a custom post is update?
- WordPress Post ids big increment
- How can I create a ‘sub-blog’ which has its own sidebar on individual posts?
- Re-Direct ALL Users to the Home Page IF not logged in
- MYSQL: Create SQL query to search for string and replace
- How to remove special characters in post title
- My page shows some other content in WP
- Query to fetch custom taxonomy along with post title
- Related post not showing table of content
- Search results with pagination not working
- My post permalinks are redirecting to the post archive page for some reason?
- How to disable WordPress from automatically changing “x” to multiplication symbol “×” when typing numbers that also contain an “x” between them?
- Not adding a new post?
- Add class to global $post
- Prevent the automatic URL linking added in last update
- how can sort my column
- How to remove the icons corresponding to “by” (author) and “date” from posts?
- Featured Story Shortcode not outputting content
- How can I display the last updated post with the author, the created date, and the modified date on one line?
- How to pull latest posts from a specific category
- Getting image data from phone camera (MediaDevices.getUserMedia) into user post
- Displaying all posts from other sites on the network on one site
- WordPress 5: prevent link from displaying page title instead of URL
- Post title links appear to be broken
- How can I make a post sub link?
- How to hide protected posts from archive?
- How to limit wordpress the_excerpt() dynamically
- the wp_post_update isn’t working all the time
- How to Best Create Separate Subscribers and User Experience
- blog post not accesible on click [closed]
- How to redirect if 404 error in wordpress then redirect 404.php url
- I want to add the 10 most recent posts under a parent category on the main menu
- Auto inserted strange characters in wp post