delete post also attachments

Maybe this works function remove_post() { if(isset($_POST[‘post_id’]) && is_numeric($_POST[‘post_id’])) { $post = get_post($_POST[‘post_id’]); if(get_current_user_id() == $post->post_author) { $args = array( ‘post_parent’ => $_POST[‘post_id’] ); $post_attachments = get_children($args); if($post_attachments) { foreach ($post_attachments as $attachment) { wp_delete_attachment($attachment->ID, true); } } wp_delete_post($_POST[‘post_id’], true); } } exit; } The code added function get_attachment_id_from_src ($image_src) { global $wpdb; $query = … Read more

Get title of post without using the_title();

This is because the_title() echos the post title (see the linked documentation). Use get_the_title() instead which returns the title as a string. Edit You have two options: Use get_the_title() to return, rather than echo, the post title Filter the_title to echo a custom string as the post title Using get_the_title() <?php // NOTE: Inside the … Read more

Different permalink for posts and authors

I would just change the author_base on the global $wp_rewrite object. Also add a field to the Permalink options page, so you can change it at will. To start: a class to wrap everything up. <?php class Custom_Author_Base { const SETTING = ‘author_base’; private static $ins = null; public static function instance() { is_null(self::$ins) && … Read more

Use an attachment in multiple posts

When inside of the media uploaded in the post edit screen, just search for your previously attached media and embed it in your new post. The relationship between posts and attachments is preserved in the database. While an attachment can only belong to one post, it can still be embedded in many posts without worry.

How can I see a list of pages and post where my custom Gutenberg block is used?

General block name search One can e.g. use the general search in the /wp-admin backend to find some text within the post’s content that stores the blocks: We can search for a prefixed block name wp:my-plugin/my-block within the posts: example.com/wp-admin/edit.php ?s=wp:my-plugin%2Fmy-block%20&post_type=post where we have an extra space (url encoded as %20and / as %2F) after … Read more

Highlight a Featured Post?

Use the “sticky” feature. In the “Page Attributes” metabox (labelled as Publish), if you click the “edit” link next to the Visibility option, there is a checkbox which allows you to “Stick this post to the front page”. Unless a theme overrides the default query, that post will show up above all the others. In … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)