How to set a template with wp_insert_post

You can check this code I am able to work with this function cutom_function() { $new_page_id = wp_insert_post( array( ‘post_title’ => ‘PKB’, ‘post_type’ => ‘page’, ‘post_name’ => ‘pkb’, ‘comment_status’ => ‘closed’, ‘ping_status’ => ‘closed’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => get_user_by( ‘id’, 1 )->user_id, ‘menu_order’ => 0, // Assign page template ‘page_template’ => … Read more

Hide Heading if ACF Field is empty

Move the outer(of the two) div.local_faq inside the if statement which checks if the faq field is set, because that’s the outer parent container. Also it would make sense to change the outer container div to have a plural div.local_faqsclass instead of the same class as the nested div.local_faq Then just add the h3 part … Read more

wp_delete_comment takes two tries to delete – then deletes all comments

The Insecure Way You need to change your form so that it includes the ID of the comment you want to delete, e.g.: <form method=”post”> <input type=”hidden” name=”comment_id” value=”<?php echo get_comment_ID(); ?>” /> <input type=”submit” name=”btn-delete” value=”try-delete”/> </form> Without this, you have no idea which comment the user wanted to delete. Then, you need to … Read more

Change product_base programmatically

Use your plugin activation hook to make the change. That will only run once, when your plugin is first activated, allowing the user to overwrite that change later (if they want to). register_activation_hook( __FILE__, function () { if ( $permalinks = get_option( ‘woocommerce_permalinks’ ) ) { $permalinks[‘product_base’] = ‘property’; update_option( ‘woocommerce_permalinks’, $permalinks ); flush_rewrite_rules(); } … Read more

WordPress get_media_embedded

Because print_r prints a readable version of your variable $media, which will be an array as per the documentation for get_media_embedded_in_content(). You see Array ( [0] => [youtube embed] ) in your browser because it’s rendering the HTML of the array element – if you check the source code of your page you would see … Read more