Category Archives: WordPress

How To Execute Woocommerce Payment Programmatically

How to trigger Woocommerce payment process like checkout but it should process in the background

To trigger Woocommerce payment process, need to call “process_payment” method. Here is an example to process Woocommerce payment programmatically.

How To Set Parenet Page For A WordPress Page Programmatically

I would like to set parent page for some WordPress pages, I knew how to update from backend. However I would like to know how can I set parent page programmatically

Set Parent Page For New Page

We can set value of post_parent which is assigning a parent page to the page when that was created.
$tmp_post = array(
    'post_type' => 'post',
    'post_title' => 'Child Page',
    'post_parent' => 'parent page ID',
    'post_content' => 'Child Page Content'
);
$tmp_post_id = wp_insert_post ( $tmp_post, true );

Set Parent Page For Existed Page​

For existed page, we can use wp_update_post to assign a parent page for a page.

wp_update_post(
    array(
        'ID' => $child_id, 
        'post_parent' => $new_post_id
    )
);

How To Disable Gutenberg Editor For WordPress 5.0

Once my site upgraded to the latest version, I can’t edit/add the page or post anymore, look like the new editor – Gutenberg has trouble with my other plugins. How can I disabled Gutenberg editor for WordPress 5.0

If you would like to disable new editor – Gutenberg for WordPress 5.0, there are 3 options

Option 1 - Install The Classic Editor WordPress Plugin

You can install the Classic Editor WordPres – Plugin Home. Once install the plugin, you can switch the editor between Gutenberg and TinyMCE

Option 2 - Install WordPress Plugin "Disable Gutenberg"

There is another WordPress plugin you can use to disable WordPress 5.0 new editor. Disable Gutenberg which is the similar plugin as “Class Editor” which is allowing you to remove Gutenberg editor complete and even “Gutenberg admin notice”

Option 3 - Disable Gutenberg editor via Code

You can place following codes within your function.php page. For the version newer than WordPress 5.0 beta
add_filter('use_block_editor_for_post_type', '__return_false', 100);
For other verions
add_filter('gutenberg_can_edit_post_type', '__return_false');
To disable Gutenberg for Meta Boxes

When adding the meta box, we can pass argument to disable Gutenberg editor.

add_meta_box('metabox_id', 'Metabox Name', 'metabox_callback', null, 'advanced', 'default', array('__block_editor_compatible_meta_box' => false));

How To Use WP_Query To Query By WordPress Post Id

How can I use WP_Query to query WordPress posts by post id or ids

Yes, you can use WP_query to query WordPress posts by post id or ids

Use wp_query to query by post id

Use wp_query to query by multiple post ids

How To Email Login Credentials To A Newly-Registered WordPress User

I have a script to create admin user account with random password automatically. However I do not know the password for the new user account, how can I get the password of the newly-registered WordPress account

You can use WordPress function – wp_new_user_notification to send out login credentials for the newly registered WordPress user.

How To Change Or Insert WordPress Yoast SEO Fields Programmatically

I have a WordPress site and installed Yoast SEO plugin. I would like to know how can I update or insert Yoast SEO fields when I create a post or page programmatically

Yoast SEO is storing meta title and meta description via post meta. You can use get_post_meta function to retrieve the Yoast meta title or meta description fields and use add_post_meta or update_post_meta to insert or update the Yoast meta title or meta description

Insert Yoast meta title / description

Update Yoast meta title / description

Get Yoast meta title / description