Yes you can pass the variable in category_name
. But I think it should be get_the_title()
instead of the_title()
.
$title = get_the_title();
$args = array(
'category_name' => $title
);
Try this. But remember category_name
only accepts category slug, not category name.
You can also use following method if your page title/slug are different. And I think it’s better.
if ( is_page( 'Page Name One' ) ) {
$cat_title="red"; // should be category slug
} elseif ( is_page( 'Page Name Two' ) ) {
$cat_title="yellow"; // should be category slug
} elseif ( is_page( 'Page Name Three' ) ) {
$cat_title="blue"; // should be category slug
}
$args = array(
'category_name' => $cat_title
);
Related Posts:
- category__not_in and id values from variable
- WP_Query not looking at child category
- Display one latest post from multiple categories
- Multiple Loops on category.php with pagination on last loop
- Pagination on category.php and tag.php not working
- Trying to get variables in hacked category dropdown
- More efficient way to list posts by category [duplicate]
- Show multiple categories in query using redux framework variable
- multiple values in an array for category__and does not work with WP_Query
- the_category() doesn’t working in wp_query loop
- WordPress Numeric Pagination with Query String [duplicate]
- Printing direct descendants of a category with WP_Query
- Custom Category Page Not Working [duplicate]
- How do i add custom post types to this query?
- Categories list loop – add separator every 3 categories [closed]
- Set colors depending on category
- Limit get_categories to show each category once
- Display single category name in woocommerce loop
- Assign custom parameter to each post in query
- Show Posts from Single Category Not Working
- Is there a reason I cannot get the current category in a loop?
- Category archive is displaying all posts rather than the specific category
- Display posts from a category
- Custom loop of a single category, cannot order by date. What am I missing?
- new WP_Query all post in a category inside the loop
- Problem with different query loops (and “main loop”) on category template page!
- How to do paging in the loop?
- How to add orderby parameter for sorting on category.php
- Use premade array as categories in wp_query?
- How to loop custom post_type from (a) specific category(ies)?
- Do not show sub categories in the loop on archive-product.php
- wp_query is showing posts from other categories
- How to display the parent category if only the child category has been chosen
- Category tags with comma’s
- Display posts of certain categories to specific user roles
- Allow user to select categories that will display in post loop
- Insert HTML content in WP Query at specific point
- Do not duplicate posts with multiple categories in multiple loops
- Simple way to style posts of a single category differently in the loop and in single
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- WP_Query with one category in args shows other categories
- Getting the Most Recent Posts from Multiple Categories
- Change post title if post has specific category
- Display subcategories in dropdown
- Display category title and three latest post inside the category
- WP_Query – using category__and when one of the categories is 0
- Display Taxonomies in loop with template args
- How to loop through a custom field for each post, & display?
- show category name before first posts in each category
- How can I modify this code to iterate over an array of categories?
- Loop within category’s posts
- Custom Post Type + Category archive
- Create multiple sections for all categories and then queries all the posts for each of those categories
- How can I display a specific number of post in a category via a url
- How to exclude a specific categogy from a custom page template
- Unable to get all tags from specific categories
- category__and works, but why?
- Display one post on category.php: Wrong featured image
- foreach,having wp_query inside, breaks after showing one result
- Display related posts with same category or same tag return blank
- $args Orderby The number
- Include category name in page template
- Loop through posts of CatA and store value of CatB in separate array
- How to add an empty entry to masonry?
- Querying Multiple Categories With Different Offsets
- Loops in category description
- How to get multiple loop in category.php, my scripts becomes madness
- Several loop in search result
- Category slug in in loop always the same?
- Make assigning post to a specific category equivalent to assigning it to all categories
- how to get number of posts in a category on a specific date
- Show posted on date only for posts in a certain category
- 2 loops in archive.php (one for each category)
- My Query is getting the wrong data
- Detecting top parent category fails on home page
- WP_query exclude a category unless it has more than one catagory
- Displaying posts by year
- Show only one category in main query, issues on tag page
- Multiple Categories under one URL, where ‘Front Page’ is used already
- Using pagination with multiple loops causes it to break
- Custom loop by url
- Custom WordPress category page showing all posts rather than the specified category
- How do I hide posts in a category from all listings but still allow the posts to be viewed?
- How to create a custom loop ordered by Categories on a Page Template?
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- Do not show all post from all categories, just show posts from category in current loop
- IF have_posts contains posts from a certain category
- WordPress loop put title into variable
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Echo Category In Loop
- How to retrieve posts from parent category, splitting them per children when displayed?
- Trying to WP_Query a category
- How can I implement pagination on custom category page?
- How to store wordpress title in a variable
- Order Categories by Character Count
- Get categories by title descendant
- Pagination only showed when no category is set in wp_query
- Elementor : display only one category in loop grid
- Different number of posts in regular loop and CPT category page