Adding additional data to WP_Post object

If your extra data directly references a post meta you don’t have to do anything, because WP_Post implements the »magic« methods __isset() and __get() which directly asks for post meta keys (except for the following four keys: page_template, post_category, tags_input and ancestors). Here’s a quick example that shows the behavior: <?php $post_id = 42; $meta_key … Read more

Delete post with all files attached to it

WP does not do this by default since there is no guarantee that attachment isn’t still being used by some other post. Basic logic would be to hook into delete_post, query for child attachments and run wp_delete_attachment() on each. I did quick search in plugin repository and came up with tiny plugin that does just … Read more

Are post ID’s reliable?

The pedantic answer is NO. While IDs are unique they can change without any change in UX as long as the change retains the consistency of the DB. And while creating a new post will generate a new unique ID, you can also create a post via code to reuse some “old” ID. In practice … Read more

How to change all the guid in posts table?

It should be something like: UPDATE wp_posts SET guid = REPLACE(guid, ‘oldurl.com’, ‘newurl.com’) WHERE guid LIKE ‘http://oldurl.com/%’; oldurl.com – Previous URL shown in wordpress settings > general options newurl.com – New URL

Customizing HTML Editor Quicktags button to open a dialog for choosing insert options

According to the Codex, you can’t do this directly through the API. However, you can do it by using your own quicktags.js file as shown below. function sample_load_admin_scripts() { if ( is_admin() ) { wp_deregister_script(‘quicktags’); wp_register_script(‘quicktags’, (“/path/to/your/quicktags.js”), false, ”, true); } } if (is_admin()) { add_action(‘init’, sample_load_admin_scripts); } Then just add Javascript to do your … Read more

Separate Database Tables For Different Post Types

So the only reason you want to re-architect WordPress to use multiple tables for different post types is because your posts table is getting bigger too fast? I assume the underlying issue for you is that performance is suffering? Instead, I suggest adding appropriate indexes to the post table for the queries you are finding … Read more

Use category base slug in posts’ permalink

I may be missing some vital detail in the question but here’s what I did to make this work. Settings -> Permalinks Set the permalinks to… /somePrefix/%category%/%postname%/ This will give you the following permalinks… Blog Page – domain.com/somePrefix Category Page – domain.com/somePrefix/currCategory/ Single Page – domain.com/somePrefix/currCategory/singlePost/ If you install some kind of plugin like Yoast … Read more

How To Have Two Gutenberg Editors On One Post?

You could add some kind of separator (a separator block?) in Gutenberg, then filter the_content() to check for the separator to display each half, by setting a switch on the first half and detecting it for the second: add_filter(‘the_content’, ‘content_splitter’); function content_splitter($content) { $separator = “<!– wp:core/separator”; $pos = strpos($content, $separator); if ($pos !== false) … Read more

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