You can do this by checking the number of results returned by your query. Try this.
<?php
$rawfiltertag = get_post_meta( $post->ID, '_cmb_client_name', true );
$filtertag = sanitize_title( $rawfiltertag );
// wp_query arguments
$args = array (
'post_type' => 'post',
'meta_query' => array(
array(
'key' => '_cmb_client_target',
'value' => $rawfiltertag
)
)
);
// the query
$the_query = new WP_Query( $args );
if ( $the_query->post_count == 1 && $the_query->max_num_pages == 1 ) {
wp_redirect( get_permalink( $the_query->posts['0']->ID ) );
exit;
}
?>
Related Posts:
- Keep getting same permalink with WP_Query?
- Plain permalinks not working!
- How to do set post permalinks using 6 digit random unique function?
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Make assigning post to a specific category equivalent to assigning it to all categories
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- Where is the old post permalink slug stored?
- Get first post from wp_query
- Change permalinks for post type ‘post’ only
- How to query serialized array by comparing greater than (>=)?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Specific loop in Shortcode
- Sort posts by activity date
- Some posts returning 404 instead of displaying post
- prevent showing posts of an specific category in admin posts section
- Link for the page archive for posts, like using custom post types with get_post_type_archive_link
- Search widget breaks when using multiple loops?
- How to change bulk post status
- Random post permalink
- If specific user role then sticky post
- Link post permalinks to subdirectory /post
- WP Query related posts by current page Tag ID
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- Custom WP_QUERY $args
- Dynamically generate child-URLs for posts or custom posts
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- List posts in a given category
- Adding parent pages to posts
- Reset Popular post query?
- Query Posts multiple conditions
- Future post ID not showing
- Search by post title and content in wp_query without order
- Move first half of posts to one parent page, second half to the other page
- Trying to use AngularJS with WordPress without any API
- Any way for get_next_post() to use the actual post order instead of publish order?
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- how do i add posts-page slug before posts slug in permalinks
- wp_query random post
- the_permalink() not working in a root installation
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- How to display all posts divided/ordered by post date? [closed]
- Is it possible to use WP_Query to only pull posts with attachments?
- Second get_permalink inside loop points to wrong URL
- Every second post different class in blog view
- Display posts of specific category term
- Can’t understand why sometimes a [caption] field appears
- Why in my query is display two title?
- wp_query with ajax
- How to give classname to post if post has no content?
- posts_per_page returning only one post
- Post is blank when I click on the link
- How to convert query sql to shortcode in wordpress?
- Use posts_where to exclude posts ids from wp_query
- Post/page title to permalink transformation – what is behind the scenes?
- Current and next month posts
- Get latest author posts inside the loop
- Same post appears in related Posts?
- Making posts permalinks consistent numbers
- How to link post titles on page A to its posts on page B?
- How can I add random alphabets in wordpress permalink posts structure
- WP_Query outputs wrong post in custom post type
- how to show comments only author which send own posts in wordpress
- Please help a newbie with blog page issue?
- Redirect old Posts URL to new URL
- How to sort WP_Post Object array by object field in php?
- Order by meta_key field in WordPress not meta_value field value
- How to add a ‘News’ section to specific posts in WordPress
- How to create page with post content in it?
- Add a url parameter to the current post and read it in a shortcode
- How to remove a post from results by ID after query?
- How can I set the permalink of an article / page equal to the permalink of an existing article / page?
- How to add category base prefix to wordpress permalink
- Override wp_link_pages pagebreak with filter
- WP_Query extended with AJAX
- Is it possible to query a category with specified posts?
- how to redirect page after delete post inside a post page?
- Permalink base only for posts
- Change the URL of posts by category
- Point users to a specific url directory for some posts
- issue in wordpress auto delete post and redirect to another 1
- post_name is not stored until post is published… where should I store my slug until it goes live then?
- Blog only showing one post even though more published
- Sort / Filter Queries
- Query to get data of a post, if in category?
- Order posts by custom field
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Order posts by separate menu order for different sub-categories
- Adding a category at even positions on main loop with modified pagination
- One of my posts is displayed as page
- Why I getting only 1 post?
- Modifying the permalink href for posts with jquery
- What is wrong with this wp_query?
- Exclude sub sub categories from displaying in the archive page
- Changes done in admin panel are taking time to reflect in the REST api responses
- Get related posts matching most of the provided tags using WP_Query