//Free AI Tools
->

Post Status Admin

Beta

Post Status Generator

Use this tool to create custom code for Post Status with register_post_status() function.
AI auto_awesome

CodeWP's AI will process this text and return the AI output. It will not account for other settings in the form, so be specific. Max words 60. AI Disclaimer

Basic Information

Specify a unique name for the PHP function that registers the new post status. This should be a valid PHP function name and unique to avoid conflicts.

Toggle this option to enable or disable support for child themes. When enabled, the post status will be available in child themes as well.

Enter the text domain for localization. This is used for translating strings and should match your WordPress theme or plugin's text domain.

Define the slug for the new post status. This should be a unique identifier in lowercase and underscores, like 'my_custom_status'.

Set the singular label for the post count. This is displayed when there's exactly one post in this status, e.g., '1 Post'.

Set the plural label for the post count. Use '%s' where the number should appear, like '%s Posts'.

Visibility

When set to true, posts with this status are publicly visible. If false, posts are private and visible only to authorized users.

If checked, posts with this status will not appear in search results. Useful for private or internal statuses.

Admin Visibility

Determines if posts with this status should be listed in the admin 'All' post list. Enable this to make posts visible in the main list.

Controls whether this status should be included in the status filters in the admin post list. Useful for quickly filtering posts by custom statuses.

Visitor Features (Login/Register)
<?php

How To Use This Tool

1. Define Your Settings
Use our Structured form to modify the code you're about to generate.
Watch A Demo →
2. Or Prompt Our AI
Alternatively, you can prompt our AI to do this for you.
Learn More About Prompting →
3. Copy code and Install
Click the generate code button, copy it, and install it on a testing website.
How To Test Code →

More Info About Post Status

References

WordPress allows developers to create custom post statuses beyond the default ones like Published, Draft, Pending, etc. This is useful for adding statuses that are specific to your site or plugin. For example, an ecommerce site may want statuses like "Awaiting Payment", "Payment Received", "Shipped", etc.

To register a custom status, you use the register_post_status() function. This function allows you to specify details about the status such as the label, whether it publicly queryable, etc.

Here is an example registration:

register_post_status( 'awaiting_payment', array(
'label' => _x( 'Awaiting Payment', 'post status', 'textdomain' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting Payment <span class="count">(%s)</span>', 'Awaiting Payment <span class="count">(%s)</span>' )
) );

Some key arguments here:

  • 'label' - The name of the status .
  • 'public' - Whether the status should be publicly queryable.
  • 'exclude_from_search' - Whether to exclude posts with this status from search results.
  • 'show_in_admin_all_list' - Show in the "All" statuses filter.
  • 'show_in_admin_status_list' - Show in the list of statuses.
  • 'label_count' - The formatted text used when displaying post counts.

Once registered, you would use this status when inserting or updating posts. For example:

$post_id = wp_insert_post(array(
'post_status' => 'awaiting_payment',
// other post data
));

Some key advantages of custom statuses:

  • They keep your data organized since you can track custom post states.
  • They integrate cleanly into native UI like status filters.
  • Lots of flexibility to map to specific business logic.

The registration process takes just a bit of code but then is easy to leverage globally. Definitely a useful tool for developers and advanced sites!

Post Status Admin FAQs

What are some good use cases for custom statuses?

Some examples are ecommerce statuses like "Awaiting Payment", "Shipping", "Refunded", support ticket statuses like "Open", "Closed", "In Progress", and content workflow statuses like "In Review", "Scheduled", "Expired".

Where should code register a custom post status?

Typically in a plugin or theme's functions.php file, or a site-specific plugin. This makes the status available globally.

What arguments can be passed to register_post_status()?

Lots of options like public, exclude search, label, show admin UI, etc. See codex for full specs.

Can posts be queried by custom status?

Yes, if you set 'public' => true posts can be queried via status parameter.

What happens if a status is not registered?

Posts will fallback to "auto-draft" or "draft". So best to handle registration properly.

Related AI Tools & Generators

Make WordPress Easy With AI
© WPAI, Inc. 2024 | d.b.a CodeWP
cross