Update post title from external file?

Sometimes I use this code when I want to run WordPress externally. update.php function find_wordpress_base_path() { $dir = dirname(__FILE__); do { //it is possible to check for other files here if( file_exists($dir.”/wp-config.php”) ) { return $dir; } } while( $dir = realpath(“$dir/..”) ); return null; } define( ‘BASE_PATH’, find_wordpress_base_path().”https://wordpress.stackexchange.com/” ); define(‘WP_USE_THEMES’, false); global $wp, $wp_query, … Read more

Programmatically change post visibility on save_post action return a 500

There is some information about this problem in the Action Reference for save post: If you are calling a function such as wp_update_post that includes the save_post hook, your hooked function will create an infinite loop. To avoid this, unhook your function before calling the function you need, then re-hook it afterward. So something like … Read more

wp_update_post onclick button using ajax

No no no! Never POST or link directly to a custom PHP file – WordPress won’t be loaded, and to load it manually yourself means making huge assumptions about the file hierarchy. Use the ajax API, which exists specifically for this reason: $.ajax({ url: “<?php echo esc_js( admin_url( ‘admin-ajax.php’ ) ) ?>”, type: “POST”, data: … Read more

Use /prefix/postname as a slug in post_name?

Well it turns out you can’t use a slash (“https://wordpress.stackexchange.com/”) in the slug but I found a solution from How to set permalink structure via functions.php, set the permalink structure in your theme’s functions.php file add_action( ‘init’, function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure( ‘/episode/%postname%/’ ); } ); It will add /episode/ before the post slug

Inline style HTML attribute is being stripped from all elements of a post

This is because what you’re trying to do trips a security feature, post content is passed through wp_kses_post to strip out dangerous tags Administrators however, have the unfiltered_html capability, which allows them to put arbitrary dangerous HTML in content and titles. This is why you’re able to insert the tags via the editor. This still … Read more

How to automatic update date and time when save custom post type

Using your example link, I just added an IF to check for post_type. function reset_post_date_wpse_121565($data,$postarr) { // var_dump($data,$postarr); die;// debug if($data[‘post_type’] == ‘new_cpt’){ $data[‘post_date’] = $data[‘post_modified’]; $data[‘post_date_gmt’] = $data[‘post_modified_gmt’]; return $data; } } add_filter(‘wp_insert_post_data’,’reset_post_date_wpse_121565′,99,2);