I suspect that your issue is occuring because the category term events does not yet exist.
If the function get_cat_ID()
fails it returns 0
, and in turn the wp_get_recent_posts()
function uses 0
as the default for the category parameter, meaning that the parameter is ignored by the function.
To avoid this behaviour I suggest you check for the result of get_cat_ID()
, and if it is 0
change it to -1
–
$events_cat_id = (get_cat_ID() != 0) ? get_cat_ID() : '-1';
$categoryPosts = wp_get_recent_posts(array (
'numberposts' => 4,
'category' => $events_cat_id,
'post_status' => 'publish'
));
For more information, please see the function reference pages for these two functions –
wp_get_recent_posts()
– http://codex.wordpress.org/Function_Reference/wp_get_recent_postsget_cat_ID()
– http://codex.wordpress.org/Function_Reference/get_cat_ID
Related Posts:
- Grab the first paragraph of each post
- Single Page WordPress Theme – Using page templates
- First post of each category
- Finding Page Template and Displaying Content
- Some doubts about how to show posts in a custom theme?
- Echo all category names, apart from one
- how to get the post attachement image in full size?
- Change image size depending on page
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]
- List categories of a post hierarchically?
- Local variable name in setup_postdata()
- How get the 10 most viewed pages (not post)
- How to close open divs in post loop
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- Sizing screenshot.png without losing aspect ratio
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- theme path in javascript file
- get_template_part vs action hooks in themes
- The the_post_thumbnail without srcset?
- The proper way to include/require PHP files in WordPress
- after_setup_theme always runs
- Do I actually need to link my theme’s style.css in the theme files
- Using classes instead of global functions in functions.php
- WordPress API Menu/Submenu Order
- How to insert a logo in the header?
- How to move page template files like page-{slug}.php to a sub-directory?
- CSS classes for theme
- Add custom classes to anchor in wp_nav_menu
- How to remove search bar from a wordpress theme? [closed]
- Should `get_template_directory_uri()` be escaped?
- Get url of thumbnail from the media uploader
- My child theme doesn’t work Error: “The parent theme is missing. Please install your parent theme”
- Get ‘page’ number with infinite scroll
- How To Add New Option Types To Option Tree?
- WP 3.4 – what action/hook is called when theme customisation is saved?
- What WP folder can I use to write files to?
- Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere
- Are the WordPress Core CSS styles really all nessesary?
- Add a dropdown to theme customizer
- Should I use set_transient or update_option?
- Why doesn’t default WordPress page view use force_balance_tags?
- Page template in two level deep folder
- Theme Customizer : how to create multiple-level panel
- Why I can’t add a CSS style in this WordPress theme?
- Theme file for all pages that are a child of a specific page
- Allow Shortcode in Theme Customizer
- Where to post/upload the new theme for WordPress theme repository
- Setting multiple default background images?
- Template for individual post designs
- How to make a theme with more than one CSS file?
- Is it good to rename theme folder downloaded from WordPress.org?
- Best practice way to implement custom sections into a WordPress theme
- Editing the custom background CSS
- What is the problem if I use CDN in my WordPress parent theme(built using bootstrap)?
- Why doesn’t /2013/01/ properly return January’s archives in archive.php?
- register_sidebar ignores ‘id’ and ‘class’
- What, specifically, should be included in theme_name_setup()?
- How to get gallery images?
- Is it possible to use line break in theme description?
- Strategy to get post meta for use outside the loop
- Is the theme customizer slowing down my site?
- How can I get wp_head() as a string instead of echoing it?
- Display a different theme for not logged-in users
- Best practice (forward compatibility) for theme options
- Automatic Updates For Private And Commercial Themes?
- Add colors to existing color palette without replacing it
- Child Theme not loading parent CSS
- What can I hook into after_setup_theme?
- Where do I find the functions triggered within a hook?
- What does “Do not deregister the jquery script in the administration area” mean?
- What is the best book to learn how to make themes for wordpress?
- add_image_size is scaling, even though crop is set to true
- Use of undefined constant FS_CHMOD_DIR – assumed ‘FS_CHMOD_DIR’
- How to show next Post Thumbnail image in WordPress using current post id
- Symlink a directory to wp-content/themes
- Pushing updates to your premium theme
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- Where can I find a good reviewed collection of Twenty Ten child themes?
- How to check if post has any tag?
- What are WooCommerce starter themes? [closed]
- How do I get gallery thumbnail URL and change the default thumbnail size?
- Front End Post Submit Form
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- A two column loop with one lead post
- How do I get a parent theme modification from a child theme?
- Removing the default sidebar from admin panel
- How do I remove RSS feeds from themes?
- Select menu on browser resize
- How to disable the gradient and font size internal CSS added by WordPress when using theme.json
- add_theme_support( ‘custom-header’ ) does not add option menu in dashboard
- Is there an error in get_the_tag_list()?
- Change loop order via form or link (jquery, not URL)
- CSS in child theme not overriding the parent theme [closed]
- Example of a theme organization without all the default wp files in root
- Is there any need to use both wp_reset_postdata and wp_reset_query together?
- Can I upload WordPress-react theme in Wp theme repository
- how to pull wordpress post comments to a external page
- Returning Variables back into a template