how to hide specific post from google search

Hook into the action wp_head, test if you are on the category archive or a single post with that category, and print the proper meta element: add_action( ‘wp_head’, ‘wpse_91073_noindex’ ); function wpse_91073_noindex() { if ( ( is_singular() && in_category( ‘CATEGORY_SLUG’ ) ) or is_category( ‘CATEGORY_SLUG’ ) ) { print ‘<meta name=”robots” content=”noindex”>’; } } Replace … Read more

post_exists() in an external script?

post_exists() doesn’t exist because you forgot to include the file where the function is declared. Looking to https://developer.wordpress.org/reference/functions/post_exists/#source you can see that it’s declared in wp-admin/includes/post.php Add this to your existing code juste after the require of taxonomy. require_once ABSPATH . ‘/wp-admin/includes/post.php’; The best way to achieve what you want is to use wp-api in … Read more

Change default screen option value for posts per page

Just an addiction to @KrzysiekDróżdż answer. When viewing a specific post status the url query string variable ‘post_status’, is set to the name of the status, so you can use $_GET[‘post_status’] to narrow the effect of @KrzysiekDróżdż code only for pending posts: function my_edit_per_page( $result, $option, $user ) { $status = filter_input( INPUT_GET, ‘post_status’, FILTER_SANITIZE_STRING … Read more

Get only modified posts

You can use the posts_where filter: // Add custom filter add_filter( ‘posts_where’, ‘wpse_modified’ ); // Fetch posts $query = new WP_Query( $lastupdated_args ); where you can define the filter callback as: function wpse_modified( $where ) { global $wpdb; // Run only once: remove_filter( current_filter(), __FUNCTION__ ); // Append custom SQL return $where . ” AND … Read more

Get post ID outside of the loop

here is a function that does just that: function get_lastest_post_of_category($cat){ $args = array( ‘posts_per_page’ => 1, ‘order’=> ‘DESC’, ‘orderby’ => ‘date’, ‘category__in’ => (array)$cat); $post_is = get_posts( $args ); return $post_is[0]->ID; } Usage: say my category id is 22 then: $last_post_ID = get_lastest_post_of_category(22); you can also pass an array of categories to this function.

Delete Post Link to delete post, its meta and attachments

Try using these delete links instead. Yours don’t seem to be formatted right. For delete: $delLink = wp_nonce_url( admin_url() . “post.php”, “post=” . $post->ID . “&action=delete”); For trash: $delLink = wp_nonce_url( admin_url() . “post.php”, “post=” . $post->ID . “&action=trash”); EDIT: No try this instead: $post_type = get_post_type($post); $delLink = wp_nonce_url( admin_url() . “post.php?post=” . $post->ID … Read more