You can use get_category( $id )
, the object it returns includes a count of posts contained in this category.
To build on your example, this would be:
$my_category = get_category( '25' );
if ( 1 <= $my_category->category_count ) {
echo "OK";
} else {
echo "NO OK";
}
Related Posts:
- Inject post (from specific category) between posts in Loop
- How can I add extra word in permalink when someone click download button?
- remove post that has no content
- How to avoid duplicates when creating recent network posts
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- WordPress query undefined offset in loop
- Only show first image in foreach loop
- Do not duplicate posts with multiple categories in multiple loops
- How to pick “full/thumbnail” images in the loop?
- Wp Query : Order by distance lat,lon
- Display articles with a different template in the home page | Solved |
- Is there anyway I can call the year once?
- Get current_post in reverse order with pagination
- Add div after every 4 posts then every 2 posts for a responsive loop
- Insert div after every three posts in home.php [duplicate]
- Automatically create a loop for post ID
- Excerpt all post content Content Same Size without word cutting off
- How to create a loop that will display one post and stop?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- Handling error states with admin_post
- Display only text to WordPress loop without loosing the text formatting
- Insert code when users come from an specific referer
- How to display related posts from parent category
- Search widget breaks when using multiple loops?
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- Way to display “Yesterday”, “Today”
- multiple if statements [closed]
- How to select WooCommerce products by post_meta and order them
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- How can I use wp_query to show all product data using just the products ID?
- Loop through categories and display posts title under each dropdown
- How to store post ID’s in cookie or session to display the same posts later
- How to set variable, pass it to a partial file and remove it after?
- Can’t find infinite loop cause
- Changing the_posts_navigation() html output
- WP_Query fails despite having 1 post
- Display related posts without a plugin
- Loop stopped working
- How to loop through all the attached images in a post, and get their url one by one
- Store post content in a php variable and output them using for loop
- Show recent posts starting at a specific number archive
- How to get the last category name of a child category?
- WP_Query: getting posts where custom field exists
- Issue with custom loop in Archive page
- Increment paged on WP_Query
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- home.php show blog posts as grid view
- get post id from wp_insert_post for get_template_part
- Displaying content on posts page based on category
- how to make an array of post id’s in is_single
- Loading Posts & Category with Ajax
- array_rand not working correctly?
- WP_Query() load selected post
- Unable to render custom field after attempt to generate a list of recent post in page template
- WordPress call post-ID in jquery
- How to extract information from a wp_query result?
- Why when I create a new post I found 2 record related to this post into the posts database table?
- List all anchor links on a page
- Defining ‘last’ class on foreach blog posts
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- understand what code is doing when prepending /blog
- My worpress search page is showing no results
- duplicate posts with ajax load more wordpress
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- update_user_meta as multiple value but with same meta key
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Time Stamp In A WordPress Post Title That Does Not Keep Refreshing
- Responsive loop with 3 columns inside row then 2 columns
- Show a text if the post has written by author user role in WordPress
- Getting info about selected posts using one WP_Query
- Change upload URL by mime type
- Related Posts: if there is no category use tags
- WordPress post insertion from PHP file
- ERR_TOO_MANY_REDIRECTS / To Force SSL Logins and SSL Admin Access
- View tag description on page
- Getting error in sql query
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- PHP tag in post content makes wordpress go crazy
- Unable to get Post Category Name and URL
- Display product attributes for current product
- Dynamically Create Posts Via XML File
- Div Missing In Custom Loop Query
- Basic PHP question (displaying post title over thumbnail) [closed]
- insert thumbnail image from php script
- media_handle_sideload() returned post_id being incremented
- Saving Post redirects to 404 page when php $_GET variable in post body
- Trying to see if page is category or single and displaying title with appropriate heading tag
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- Transient Loop Not working as expected
- Conditional in foreach loop is outputting content twice
- is there away to hide php code in wordpress not to show in PAGES
- Woocommerce linking variations
- I want to show image from custom field image on my custom page template
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress