How to prevent WP from inserting empty posts

Due to auto-save’s the post will always exist in WordPress, it’s inserted into the database as soon as content is entered. So you can’t prevent an entry, – however you can filter after a user hits “Publish” or “Save” on the post using wp_insert_post, or save_post. With this action you can do your conditional checking … Read more

Not able to post data through wp-admin

I recommend to try by debugging the code, might be there is an issue because of a New version of PHP. Try by writing this code into the wp-config.php file and see what if any error: // Enable WP_DEBUG mode define( ‘WP_DEBUG’, true ); // Enable Debug logging to the /wp-content/debug.log file define( ‘WP_DEBUG_LOG’, true … Read more

How to wrap image tag into div for post only?

You have the global WP_Post object available so you can look the post type like this: function wrap_post_images_to_div( $content ) { if ( get_post()->post_type === ‘post’ ) { $pattern = ‘/(<img([^>]*)>)/i’; $replacement=”<div class=”well text-center”>$1</div>”; $content = preg_replace( $pattern, $replacement, $content ); } return $content; } add_filter( ‘the_content’, ‘wrap_post_images_to_div’ ); You can use the preg_replace_callback instead … Read more

How do if all posts has this category ID then do this

You can use get_category( $id ), the object it returns includes a count of posts contained in this category. To build on your example, this would be: $my_category = get_category( ’25’ ); if ( 1 <= $my_category->category_count ) { echo “OK”; } else { echo “NO OK”; }

How to display the pagination in my post list? [duplicate]

You’re having pagination issues because you’re using a custom query and both previous_posts_link and next_posts_link use the default query to calculate and display the pagination. This problem is explained in-depth in both this and this answers to similar questions. If the only reason for you to be using a custom query is for defining the … Read more