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?
- How to check if I’m on the last page of posts?
- Should category.php and The Loop be used if the query needs to be customizable?
- Exclude the category from the WordPress loop
- Exclude categories from search query
- get_field not displaying my custom field value
- Randomise results from a category page?
- Show div only if post is in specific category
- How to show a category post to a specific registered user
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Custom query with category exclusion and post-meta “whitelist”
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Exclude most recent posts from specific category in wp_query()
- Listing all posts from current category on page
- How do I get the total number of categories in a list of search results?
- Query Custom Post by Category
- Display products for a category, sorted by post_excerpt
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- a-z list, categories and sub categories in loop
- How to loop only categories without posts (+ show category featured image with acf) [closed]
- Additional featured post on first page
- Show all posts for a specific category/author
- create a page which displays a list of categories title+ short description?
- Pagination for category slug returns 404 when page >= 2
- Class active for Archive link – looped out
- Taxonomy name repeating when showing 2 posts from each category
- Counter in loop in foreach
- How to exclude the last post from a category(featured for example) from the main loop?
- Order by category titles
- Inside a loop, how to change CSS class based on category name?
- Limit get_categories to show each category once
- 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
- new WP_Query all post in a category inside the loop
- 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
- Allow user to select categories that will display in post loop
- Do not duplicate posts with multiple categories in multiple loops
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Getting the Most Recent Posts from Multiple Categories
- 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
- Query posts by views on category page
- filter a loop base on specific category
- Are term_taxonomy_id and term_id the same? [duplicate]
- Using in ‘category_name’ in ‘$query->set();’?
- Custom Page Template Category loop not functioning correctly
- Limit Loop to One Category
- Filter Category Loop Dynamically
- How can I use AJAX with check-box categories?
- Editing Loop So It Targets Specific Tags?
- Select posts that match multiple category names, must match all categories listed
- Conditional category query breaking?
- Problem: retrieving parent category’s first post
- Category name for all posts getting assigned to a single random post
- Category post count is not correct
- Include last post date in get_categories loop
- How to get specific (grand parent) category of current post?
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- Custom Loop with certain number of one category
- how tho change number of posts in loop from specific categories
- Template category.php with page (no posts)
- Get categories within specific term
- error in specific category loop
- loop in single.php of the same category
- Please tell how to stop the category from showing up on posts
- Hide a category/posts from the homepage in wp
- Trying to display all posts in a category
- Display Taxonomies in loop with template args
- How to exclude a specific categogy from a custom page template
- Unable to get all tags from specific categories
- Querying Multiple Categories With Different Offsets
- How to get multiple loop in category.php, my scripts becomes madness
- WP_query exclude a category unless it has more than one catagory
- Show only one category in main query, issues on tag page
- Custom loop by url
- 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
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Trying to WP_Query a category
- How to store wordpress title in a variable