Sending a custom form data in email through WP Mail Function

I would suggest using AJAX for this. You could do something like this for the jQuery part: <script type=”text/javascript”> jQuery(document).ready(function($) { // Execute when user clicks on the “Submit” button $(‘#SUBMIT_BUTTON_ID’).on(‘click’, function(e) { e.preventDefault(); var email = $(‘input[name=email]’).val(); var firstname = $(‘input[name=firstname]’).val(); var familyname = $(‘input[name=familyname]’).val(); var other_names = $(‘input[name=other_names]’).val(); var dob_day = $(‘input[name=dob_day]’).val(); var … Read more

Merge two search functions for custom post type

Your functions are already simple enough, and secondly, the functions do different things: _s_staff_query() filters the posts query variables and the function has to run before WP_Query queries the database. _s_staff_search() filters the search results template and the function has to run after WP_Query queries the database. So just keep them independent.

How to change this simple code so that it sends the email notification after payment in WooCommerce?

The hook you’re looking for is “woocommerce payment complete” and it’s triggered once an order has been marked as “complete”. In the function called by that hook, you need to grab all coupons applied to the order, and check if any of them is the one you’re looking for. add_action( ‘woocommerce_payment_complete’, ‘so_payment_complete’ ); function so_payment_complete( … Read more

Is my code correct to enqueue CSS on a specific page?

Try this: I hope, It will works. Explaination: In below code in “is_page( 42 )” where 42 is page id of about page. So, if about page’s id will be 42 then it’s enqueue the stylesheet for that page only. Also I define particular path for this CSS file by using wordpress function get_template_directory_uri(). function … Read more

How to set default post editor based on role?

create_function() is deprecated as of PHP 7.2.0, so you should avoid using it. Instead, use an anonymous function. Additionally, it’s better the check the current user role inside the callback function, so that the current user role is checked when the filter is applied, not when the hook is added, which could be before the … Read more

Notify users only on post publish

You could use the transition_post_status hook instead, as it already knows what the current and previous status of the post are. <?php add_action(‘transition_post_status’, ‘wpse_366380_email_on_publish’, 10, 3); function wpse_366380_email_on_publish( $new_status, $old_status, $post ) { // Only if this post was just published, and previously it was either // “auto-draft” (brand new) or “pending” (not yet published) … Read more

Find hours between post_date and post_date_gmt

If all you need to do is check the difference, rather than display or modify anything, then you don’t need to do anything complicated with date_diff(). All you need to do is compare the number of seconds returned by get_post_time() for each date. get_post_time() returns the Unix timestamp for the date, which is simply the … Read more