Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to change your default wordpress post category & post type?



How to change your default wordpress post category & post type?..

Answer / Rishabh

To modify the default post category or post type in WordPress, you'll need to edit the functions.php file for your active theme. Here's an example of how to set a custom default category:nn```phpn// Set a custom default category IDndefine('DEFAULT_CATEGORY', 1);nn// Function to create or get the default category if it doesn't existnfunction my_default_category() {n return (int) get_cat_by_slug(get_option('default_category'));n}nn// Filter the default category ID before a new post is createdndefine('pre_post_updated', 'my_set_default_category');nadd_action('pre_post_updated', 'my_set_default_category');nfunction my_set_default_category($post) {n if (empty($post->ID)) return; // Ignore new posts without an IDnn // Get the default category IDndefined('DEFAULT_CATEGORY') or define('DEFAULT_CATEGORY', 1);n $default_category = my_default_category();nn // Set the default category for the postnwp_set_post_categories($post, array($default_category));n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More WordPress Interview Questions

Explain me what are the custom fields in wordpress? How to display it?

1 Answers  


What is a taxonomy in wordpress?

1 Answers  


How do I set up a subdomain?

1 Answers  


How do I start a blog from scratch?

1 Answers  


How do you create a page in wordpress?

1 Answers  


How do you create a blog page?

1 Answers  


What is wordpress good for?

1 Answers  


What is a template on a website?

1 Answers  


Can I monetize my wix blog?

1 Answers  


What are meta-tags in wordpress?

1 Answers  


Is a website on wordpress safe and secure?

1 Answers  


Where is wordpress database stored?

1 Answers  


Categories