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?
- How to add custom css file in theme?
- get_template_part vs action hooks in themes
- How to remove search bar from a wordpress theme? [closed]
- Get url of thumbnail from the media uploader
- Should I use set_transient or update_option?
- Template for individual post designs
- Best practice way to implement custom sections into a WordPress theme
- Pushing updates to your premium theme
- Where can I find a good reviewed collection of Twenty Ten child themes?
- Front End Post Submit Form
- How do I remove RSS feeds from themes?
- Change loop order via form or link (jquery, not URL)
- CSS in child theme not overriding the parent theme [closed]
- Advantages of using instead of wp_enqueue_style()?
- Style.css redirects to 404 Page not found
- Displaying wp menus by name without using theme locations
- How to add dynamic inline style?
- Optimal solution to develop a wordpress theme?
- How to add suggest plugin to theme?
- Why does this loop only work on the homepage?
- Prevent update check for specific theme
- Do I really need the div class entry?
- Am I supposed to create a child theme for every theme I use?
- using wordpress without javascript
- Theme Check: Could not find post_class
- Why wp_head() function not loading style.css?
- Override theme programmatically
- Set multiple templates per post
- WP 3.1 upgrade breaks AutoFocus+ theme
- How can I display/hide certain content based on a Theme Option field?
- create-guten-block in wordpress theme?
- How can I make that when I clic on one of the menu items, that page shows only posts with the same category?
- Displaying recent post excerpts on static front page
- Theme Splash Image within the “Appearance -> Themes” control panel [duplicate]
- Theme Loading Into Dashboard
- How to make theme elements customizable in wordpress?
- How to add “Template” option in page attributes panel?
- Which html elements should be styled in wordpress theme
- Custom get_the_excerpt() only works on first post
- Folder name for a pro version of a WordPress.org theme?
- Admin: sub menu doesnt display under apperance when activate my themes
- Does code in function.php differ from theme to theme
- Create a child theme from multiple themes
- Are seven additional image sizes are too many?
- registering a global template wordpress 6.0
- Copying the theme style files and images to duplicate the website but with a difference
- I have WordPress setup on primary domain, how do I set it up on its subdomain using the same database?
- How to set Post meta-box defaults based on the choices made by user in Customizer?
- home.php show blog posts as grid view
- Theme Action to hook for one time only function [duplicate]
- Twenty Seventeen Pages Loop
- How do I include a partial from a directory below a wordpress theme directory?
- How does the loop know which post to view?
- How to remove permalinks links presents in each page of my site?
- HTTP Error when uploading images over specific dimensions
- Why is the `if else` not working?
- showing all recent posts in theme
- iPad WordPress theme?
- custom Background not showing after upgrade?
- Rolling your own WordPress Themes
- How to make a function occurs for one time?
- PHP Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE), expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) on line 124
- How to display home page last modified date in anywhere of wordpress theme?
- Loop is breaking my theme. How can I fix?
- Is there a way to create sections under “Colors” panel in the Theme Customizer?
- Is a multipurpose theme an alternative to modifying or creating a theme from scratch?
- WooCommerce – edit templates
- WordPress Custom font not found
- How to dowload and edit content of a website
- Best strategy for providing theme options using customizer
- Next post in category
- Magnific Popup – Add Caption to Images
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- Trouble creating custom sanitization function when uploading video files
- What’s the policy for building a theme that doesn’t support widgets/menus?
- How Does One Create a Global Variable Repository
- Suppress the_content filter in a nested loop
- wordpress taxonomy results
- The normal loop with different styles doesn’t work in search.php
- Not Found when using activity stream as front page with BuddyPress
- Any Cool WordPress Theme Editor? [closed]
- How to remove proudly created by WordPress in theme?
- Roll my own theme or customize an existing one [closed]
- Why do some sites show themes/”themename” as the only theme?
- How do I send out an update for my custom wordpress theme?