WordPress shortcode returns the data before

Change form.php <form action=”<?= $_SERVER[“REQUEST_URI”]; ?>” method=”post”> <input type=”hidden” name=”form_submit_nonce” value=”<?php echo wp_create_nonce(‘form-submit-nonce’); ?>”/> <label for=”id”>ID</label> <input id=”id” name=”id” type=”text” value=”” required /> <input type=”submit” name=”submitid” value=”Submit”> </form> Change plugin file function form_shortcode(){ if ( isset( $_POST[“submitid”] ) && isset($_POST[‘form_submit_nonce’]) && wp_verify_nonce($_POST[‘form_submit_nonce’], ‘form-submit-nonce’) ) { echo “<p>OK</p>”; } else { include “form.php”; } } add_shortcode( … Read more

How to create a field in customize and show that in header.php?

add_action( ‘customize_register’, ‘theme_customize_register’ ); /** * Register individual settings through customizer’s API. * * @param WP_Customize_Manager $wp_customize Customizer reference. */ function theme_customize_register( $wp_customize ) { // You can first start by adding a section $wp_customize->add_section( ‘theme_options’, array( ‘title’ => __( ‘Title of your section’, ‘domain’ ), ‘capability’ => ‘edit_theme_options’, ‘description’ => __( ‘Some description’, ‘domain’ … Read more

How to relocate paypal button gateway on checkout page in woocommerce

Have you tried this? E.g. the paypal button function name is woo_custom_paypal_button. Then add action like this into your function.php or specific plugin: add_action( ‘woocommerce_checkout_before_customer_details’, ‘woo_custom_paypal_button’ ); Or if there’s something that’s already displayed there, and you might want to remove it, first find the function name and then try like this: remove_action( ‘woocommerce_checkout_before_customer_details’, ‘woo_function_to_remove’ … Read more

Correct PHP to output a single result of a Function with SQL Query

Solved it! Amazing what a good nights sleep does! Function: function get_all_rating_criteria_travel6(){ global $wpdb; $rating6 = $wpdb->get_var( ‘SELECT RatingCriteriaText from ratingcriteria WHERE NicheID=1 AND StarRatingID=5;’); echo $rating6; } Code to display: <?php get_all_rating_criteria_travel6(); ?>

Simple WordPress endpoint route doesn’t work

Exact namespace prefix and non-empty endpoint name helped me: add_action(‘rest_api_init’, function () { register_rest_route(‘vku/notifications’, ‘test’, [ ‘methods’ => ‘GET’, ‘callback’ => function (WP_REST_Request $request) { error_log(‘Route “notifications” works’); return new WP_REST_Response(true, 200); }, ]); });

Different options per post type in WP_Query

You could use pre_get_posts to conditionally add the tax_query depending on post-type, here’s a simple example. <?php function wpse_377928( $the_query ){ $post_type = $the_query->get(‘post_type’); if ( ‘type_a’ === $post_type ) { $tax_query = [ [ ‘taxonomy’ => ‘tax-1’, ‘field’ => ‘term_id’, ‘terms’ => array(11, 12, 13), ] ]; } elseif ( ‘type_b’ === $post_type ) … Read more

how to serialize() mysql update data

You should not use raw SQL to modify roles and capabilities, it is very bad practice, and unnecessary. Instead, use the roles API, e.g. $role = get_role( ‘subscriber’ ); $role->add_cap( ‘read’ ); Or to add it to a specific user: $user = new WP_User( $user_id ); $user->add_cap( ‘read’ ); Likewise you can remove a capability … Read more

malware undetectable by multiple scans

There are many ways to infect a site – and many ways to hide that infection from the ‘popular’ security plugins. One way to detect malicious code is via a file-hash-compare function. You may need to write your own though (I did, but it’s not perfect). That function would compare each file’s hash with a … Read more

How to Update post_modified of all wordpress post

You can use a generalized update query. As always, when dealing with databases take a backup first. With that out of the way, your query should look something like: BEGIN; — Start a transaction UPDATE wp_posts SET post_modified = <Your new date> AND post_modified_gmt = <Your new date in GMT>; SELECT * FROM wp_posts LIMIT … Read more