Sort / display recent posts by publish date

The Recent Posts widget, and the posts page for that matter, doesn’t display ordered by update date, it orders by published date. If it’s displaying by updated date then you must have a plugin somewhere that’s changing this behaviour, or are using something other than the standard Recent Posts widget.

how to execute some code after a post is published in WordPress [duplicate]

You’re looking for the save_post action. This allows you to add a function when a post is saved (updated). You can hook into it like this: function your_save_post_function( $post_id ) { } add_action( ‘save_post’, ‘your_save_post_function’ ); Remember to not change WordPress Core files, as these will be overwritten when WordPress is updated. You can put … Read more

After I publish a post where does it go

You can just delete the posts from your wordpress site, but you are likely going to want to look at the media section of your wp site, as if you have many videos or photos on your site, those will take more space than just a post. When in your wp admin panel, on the … Read more

How to add publish date in the title

if the output you see is ABC [post_published], then it means your shortcode isn’t working as it should. try including following code at the end of inside your theme’s functions.php file. function ppd_shortcode(){ return get_the_date(); } add_shortcode(‘ppdate’, ‘ppd_shortcode’); When you register a shortcode using the add_shortcode function, you pass in the shortcode tag ($tag) and … Read more

What is the reason for the new_to_publish hook not working?

When you create a new post, the initial post status is not new, but rather auto-draft. Try this: add_action(“draft_to_publish”, “doSomething”, 10,1); function doSomething($post){ global $post; $_SESSION[‘yeni’] = ‘test’; } echo $_SESSION[‘yeni’]; Also note that you may want to make sure your session is properly initialized. To verify the callback works at least, enable WP_DEBUG and … Read more

WordPress publish_post hook not getting featured image and meta on first publish, but works on updating title

I don’t know if it’s the Gutenberg editor or if it’s the hook publish_post The hook itself works, and if you used the old WordPress post editor, then the issue in question would not happen. So you can say that it’s the Gutenberg/block editor. why it’s not returning the meta and featured image Because Gutenberg … Read more

WordPress bulk category select when publishing post

The default function that renders the categories meta box is post_categories_meta_box – it doesn’t have any internal hooks we can use to inject our own HTML, so let’s create our own meta box handler and just use the function internally: function wpse_406861_post_categories_meta_box( $post, $args ) { post_categories_meta_box( $post, $args ); echo <<<HTML <label> <input type=”checkbox” … Read more

Stop wordpress from creating empty/null entries

When i needed a solution to the save “problem” i create an Ajax function to validate the fields and did some minor JQuery hacks: first we add our JavaScript to capture the submit/publish event and use it to submit our own ajax function before the actual submit add_action(‘wp_print_scripts’,’my_publish_admin_hook’); function my_publish_admin_hook(){ if (is_admin()){ ?> <script language=”javascript” … Read more