The in_category
function works only on existing (saved) posts. Here you can directly access the category in $postarr
like this:
if ('affitti' == $postarr['post_category'])) {
wp_die('Error: Posts cannot be published with the default category.');
}
By the way, are you sure you want to use wp_die
for this and not some other error message? People may loose their work if WP stops completely when they try to publish.
Related Posts:
- Get posts with at least one category in common with current post?
- Add a specific part of current category page url to shortcode
- Multiple Tag Filtering
- How to filter specific element of an array in wordpress/php?
- dynamically filter by category via sub-menu
- Display featured posts first, then display all others within a specific category in WordPress
- add_action shortcut?
- Is it acceptable to treat a filter like an action?
- Proper syntax or method for keeping url in modified isotope / category links
- Filter Select results based on selection
- What is an equivalent of single_cat_title for getting the slug of the category?
- How can I remove a function that has been added to wordpress with add_filter?
- Issue adding sub category programmatically
- How to control WordPress image metadata (using Imagick)?
- Edit incorrect password message WordPress
- How do I add custom bulk actions to multiple custom post types?
- Add data attribute to each li in menu
- Show prices with tax in Woocommerce Mini Cart [closed]
- Ajax category filtering products default show all
- How to exclude category ID from Looper in WordPress
- how do I get a specific post from a post with a subcategory in WP
- Why does my callback function not work with this custom filter hook?
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- Move category description below post list in blog
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- Removing “wpautop” (auto tags) only on certain pages?
- How to pick the default selected value in wordpress dropdown?
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- Add filter when image is uploaded?
- Remove the first 5 characters of the_title and orderby that
- Remove a div from RSS feed
- Print last modified date only on posts
- How to add an arrow to menu items has submenus
- WordPress Gravatar filter is removing my custom attributes
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- selected option if current category is the value
- Unique icons next to each WordPress menu item
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Hide subcategories (widget)
- Alert Bar section within WP loop is displaying even though there are no posts
- Let Users Choose Post Categories
- Different post styles depending on category
- Display category name only once inside loop
- Change tinyMCE editor to allow marked content when pasting from Word
- Problem with login form
- How to show only subcategories in parent category not parent category?
- how to show only specific category for a template
- Redirect to another page using contact form 7? [closed]
- Alter required message using comment form api
- How to debug this search & replace strings snippet?
- Hide Featured Image Meta Box on Editor Screen
- Dilemma of Populating all the categories in a drop down list
- Add item to top of menu using a filter in functions.php
- Display most popular posts of category
- Add filter multiple times using only one master function
- Creating sub-categories via php
- How to edit php code in WordPress Post file?
- Change page title from page using php via php executed from page/post itself
- Define specific category name in PHP
- How to make modifications only to certain elements of an HTML string on the server-side?
- Override a function defined in wp-includes/comment-template.php
- Edit the_category (); for a hierarchical display
- JSON REST API WordPress only showing first 10 categories
- Category title output before opening title tag
- get taxonomy thumbnail and use it as a variable in code
- Include Parent Term in wp_list_categories
- How to array only one key from another array
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Filtering a function’ output for a new continued function
- Get all categories post is not in
- Get latest post from all categories except one
- Displaying posts based on category
- Deleting Certain terms from appearing on the front end as links
- Content filter won’t work
- How do I remove a category from a wordpress loop>
- Get categories names as an array to use it in theme settings
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- How to get the last category name of a child category?
- Warning: in_array() null given in PHP function
- Upload multiple files in randomly generated folder using wp_upload_bits
- Create page template via functions.php?
- Add meta tags to a custom header
- Ajax filter button display all posts
- How to append to an array and return the results in a filter?
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Use get() method to grab all categories and output inside another method
- Only show size attributes in product box woocommerce when available
- How to have different site identity logos on each page on Astra Theme [closed]
- How to get category name or ID by post?
- Custom post type category not displaying category ID
- Argument for if term-> have child?
- How to get current post category details inside “loop”?
- How to separate categories with commas?