Check if current user has a post and that post has any term/s from a specific custom taxonomy outside the loop

This can be done using WP_Query using author and tax_query. Something like this: $args = array( ‘post_type’ => ‘post’, ‘author’ => get_current_user_id(), ‘tax_query’ => array( array( ‘taxonomy’ => ‘custom-taxonomy’, ‘operator’ => ‘EXISTS’ ), ), ); $query = new WP_Query( $args ); And then check if posts are returned through this query. Please note that this … Read more

Edit the post title from the frontend

Yes, you can change post title and slug from frontend. by using wp_update_post you can change title and slug of post. in below code, it will update post title and slug of post_id. Replace your-post-title-field with your title field in form. slug will generated using that post title. if ( isset( $_POST[‘my_image_upload_nonce’], $_POST[‘post_id’] ) && … Read more

Replace image name on upload to the new post name on front-end form

You can use sanitize_file_name filter to rename file. put this code in active theme’s functions.php, this will rename image filename as postname if only get title request. I have tested this code and it is working fine. Post name : https://prnt.sc/q3thzw Uploaded renamed image : https://prnt.sc/q3tib7 function make_filename_as_post_name($filename) { $info = pathinfo($filename); $ext = empty($info[‘extension’]) … Read more

What is $post->pre_post_content exactly?

There’s no such thing. pre_post_content is a filter that allows you to filter the result of sanitize_post_field() for the post_content field of posts. But the standard WP_Post class, which $post usually is, does not have a pre_post_content field. If $post on your site has such a field, then it’s likely being added by a plugin, … Read more

I can no longer post or even save a draft, getting the error “A post type mismatch has been detected.”

In my version of WordPress this error will come from line 46 of wp-admin/post.php, which has: if ( isset( $_POST[‘post_type’] ) && $post && $post_type !== $_POST[‘post_type’] ) { wp_die( __( ‘A post type mismatch has been detected.’ ), __( ‘Sorry, you are not allowed to edit this item.’ ), 400 ); } The code … Read more

Why is my custom template not showing anything?

The template for displaying all your posts should not be a custom page template. You should set the page you want to use as your Posts page in Settings > Reading. Then, as per the Template Hierarchy, your theme will automatically use home.php for this page, or index.php if that does not exist. So you … Read more

Force a specific template as default

Instead of setting yourtemplate.php as the default, why don’t you change the default template, and put the original default in yourtemplate.php? AKA swap them? Otherwise you’ll have to go back through all your posts and change them, and, mess around with complicated filters that might not work 100%