Hook template_redirect
and check if it’s a category archive page, if so get the category ID from query_vars
and query_posts
for a single post from that category, which by default should be the most recent, then wp_redirect
to the post’s permalink.
This code would go in your theme’s functions.php
file:
function my_category_redirect() {
if ( is_category() ) :
query_posts('cat=". get_query_var("cat') .'&posts_per_page=1');
wp_redirect( get_permalink() , 301 );
exit;
endif;
}
add_action( 'template_redirect', 'my_category_redirect' );
Related Posts:
- exclude category from get_posts?
- Get id of category from drop down menu
- Show post only if match all categories
- Show recent posts from one category on a non-WP site
- get_posts and multiple categories
- Trying to only display 1 category using get_posts
- Get link which associated with a specific category and tag
- Get posts from 2 different categories
- Get posts from specific taxonomy term
- List all posts in a category with query_post() function
- Hooking to walker_nav_menu_start_el to insert list of subpages
- get_posts ignoring ‘category’ and displaying all posts
- How to pull a list of posts in a category while exluding posts in subcategories of the category
- How to Link to Most Recent Custom Post of Same Term
- get_posts() from parent category only using a shortcode
- Exclude parent category when getting category posts by slug
- Exclude categories from homepage not longer working
- Showing posts from 2 categories only on category.php
- get all categories’ latest post in one query
- get_the_category return empty inside loop
- Get posts base on category ratio of more then two categories
- Media Library Category Exclude Tree
- not empty categories don’t show in menu [closed]
- how to call the category of the post
- How to create a custom loop ordered by Categories on a Page Template?
- How to change category id on get_posts array
- get posts from 2 categories. (2 posts)
- how to ask if in two categorys inside if
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Display list of Sub-Categories and the posts they contain, within one main Category
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Category Specific Archive
- Is there a plugin that will completely remove the category system?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- How to get only the last child of category slug?
- Multisite – create a category in specific site
- How to list only child categories?
- How do you remove display of WooCommerce product category on single product page?
- Show recent posts in menu?
- Cannot add / edit categories to a post anymore
- List archived posts by subcategory
- What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?
- Convert the default sub-category dashes to bullets or any other characters
- How to check category of of custom post type or not
- Set a them for all subset of category
- How to query post like normal search would do. within search.php page
- WordPress Get Posts from each category equally
- Unwanted Duplicate Product Categories in WooCommerce
- WP admin broken. Not saving catgories or adding categories to menu
- Set colors depending on category
- get_terms function not returning anything
- Why custom taxomony not showing when create a post?
- Getting All Post From Specific category in wpdb
- Single.php Category Post Count
- wp_list_categories with show_count, except for specific categories
- Show the amount of posts in a tag in a specific category has
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- How do I add a category to my post_type
- How to get posts by category and by choosing a taxonomy term?
- Add posts of a certain category to a page
- Show 10 Sub Categories Per Parent Category Page?
- Conditional category & tag statement
- How to remove the category from post slug
- Post Loop Category first show parent then child
- How to display posts from specific category using get_option function?
- Post not found when filtered by category ID
- How to detect /category and /tag base pages?
- can I ‘combine’ categories as a menu item?
- List taxonomy terms assigned to a post in hierarchical view
- Hide category name but show posts
- Count how many posts have a specified tag AND category
- Show the parent taxonomy by creating shortcode in woocommerce?
- Post List by category and under custom taxonomy
- Balance Tags to the_content Words Length
- How to create template for children category?
- Categories and Tags Conflict after Woocommerce Installation
- how to display categories for a specific post?
- the_content() not showing full posts in category template
- Show parent category if there is no subcategory
- Add category links?
- foreach,having wp_query inside, breaks after showing one result
- Display a category name automatically using code in the functions.php file
- Removing categories, Comments etc from posts?
- Add html word before category
- Problem importing categories and sub-categories
- How to show video from wp option value?
- Changing Woocommerce categories programatically
- Add an Exclusive or featured tag line to article titles
- How to list out post category name and description in page
- Print child category slug nicename
- Order Categories by Character Count
- Custom EndPoint not working when strip child category in URL
- How to add custom prefix before category base for category page URL?