How to filter content post only on save

Look at ‘save_post’ and Post Status Transitions. save_post is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. The data for the post is stored in $_POST, $_GET or the global $post_data, depending on how the post was … Read more

Content editor creating blank paragraphs in spaces and creating &nbsp in the_excerpt

Judging from your site’s content and the comments, you may try using the following CODE in your theme’s functions.php file. It’ll remove empty <p>&nbsp;</p> tags from post content: add_filter( ‘the_content’, ‘wpse_257854_remove_empty_p’, PHP_INT_MAX ); add_filter( ‘the_excerpt’, ‘wpse_257854_remove_empty_p’, PHP_INT_MAX ); function wpse_257854_remove_empty_p( $content ) { return str_ireplace( ‘<p>&nbsp;</p>’, ”, $content ); } However, after it removes the … Read more

Pagination not working on custom query

The pagination functions work off of the main query, so you’d need to use pre_get_posts instead of creating a new query for them to work. But, you’re using WP_User_Query, so the standard pagination system will never work for you. You’re going to have to ‘roll your own’ pagination system here, and generate your own URLs … Read more

Using a javascript file to access a get posts array

Yep, you’re looking for wp_localize_script(). Do away with the global. add_action( ‘wp_enqueue_scripts’, ‘wpse_enqueue_scripts’ ); function wpse_enqueue_scripts() { wp_enqueue_script( ‘wpse-main’, get_template_directory_uri() . ‘/path/to/script.js’, array(), false, true ); wp_localize_script( ‘wpse-main’, ‘wpseVars’, array( ‘postsLoop1’ => json_encode( /* first post array */ ), ‘postsLoop2’ => json_encode( /* second post array */ ), ‘postsLoop3’ => json_encode( /* third post array … Read more

Future_to_publish into postmeta

Use publish_future_post action hook. Contrary to what Codex says, it is not deprecated, and it works with WordPress 4.8.2. Your code should be: function my_test_future_post( $post_id ) { update_post_meta( $post_id, ‘hook_fired’, ‘true’ ); } add_action( ‘publish_future_post’, ‘my_test_future_post’ ); Tested! Update If you are concerned about publish_future_post hook being deprecated, use transition_post_status hook: function my_test_future_post( $new, … Read more

Remove image from post also removes photo from media library

Don’t know if there is an easy way out but you can do this to achieve: Introduce an admin js in your functions.php like this: //Admin JS add_action(‘admin_init’, ‘custom_admin_js’); function custom_admin_js() { wp_register_script( ‘admin-js’, get_stylesheet_directory_uri() . ‘/js/admin.js’ ); wp_enqueue_script( ‘admin-js’ ); } The js file will go in the theme you are using make another … Read more

Undefined variable post_id in custom quick edit coloumn

Sorry, I’ve had to change my answer after checking the WordPress Codex on adding custom editable data to the quick edit. So you’ll have to remove the references to $post_id too (from the add_action arguments and from within your function). It looks like the quick_edit_custom_box only takes 2 arguments: $column_name and $post_type. Then for getting … Read more