javascript variable to wordpress php variable

First you need to to send function name as additional data as $.ajax({ type: “POST”, url: compareids_ajax.ajax_url, data: { // Data object compareIDs : compareIDs, action: ‘your_ajax_function’ // This is required to let WordPress know which function to invoke }, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (msg) { console.log( msg ); }, error: function … Read more

Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]

The meta box template for the variations is defined in the file html-variation-admin.php. There you will find the hook “woocommerce_variation_options_pricing”. With this hook you can add your input field to the desired place. function variation_settings_fields($loop, $variation_data, $variation) { // Your Text Field woocommerce_wp_text_input( array( ‘id’ => ‘_text_field[‘ . $variation->ID . ‘]’, ‘label’ => __(‘My Text … Read more

Post URL based on Custom Post Types variables

Instead of creating a new tag, I would suggest just writing code to create the slug on a per-post basis using ACF’s save_post function. //Update Cars slug field: function wpse_post_slug_updater( $post_id ) { if( get_post_type() == ‘cars’) { $my_post = array(); $my_post[‘ID’] = $post_id; $my_post[‘post_title’] = esc_html(get_the_title($post_id)); $my_new_slug = get_field(‘brand’) . ‘ ‘ . get_field(‘license_plate’); … Read more

Turning variable into a value set in shortcode

I want the $icon variable to become the value of icon attribute of custom-link I set: If I understood your question correctly, this is what you want, function custom_link($atts, $custom_title) { include “PATH_TO_YOUR_PHP_FILE_CONTAINING_ICON_VARS”; $url = $atts[‘url’]; $color = $atts[‘color’]; $icon = $atts[‘icon’]; $icon = $$icon; // $$icon is $icon_paypal return ‘<a class=”button-round custom-link” style=”background-color: ‘ … Read more

How to access or parse key/values that have “string”

In it’s current state you would directly get the value from the associative PHP array by directly referencing the key like so: var_dump( $form_data[‘key’] ); It’s wise to note that when you dump variables using var_dump you get information on the value type, and length. So in this case you get string(33) which indicates the … Read more

Undefined variable error in new function

I believe that’s telling you that $post (in $post->ID) is undefined. Try this instead: function sh_reading_time() { $content = get_post_field( ‘post_content’, get_the_ID() ); $word_count = str_word_count( strip_tags( $content ) ); $readingtime = ceil($word_count / 200); if ($readingtime == 1) { $timer = ” minute”; } else { $timer = ” minutes”; } $totalreadingtime = $readingtime … Read more

Pass Variables or Variable Place-Holder from Editor to PHP

You should use str_replace, which accepts arrays as arguments: $content = “Email: {{email}}\nFirst Name: {{first_name}}”; $body = str_replace( [‘{{email}}’, ‘{{first_name}}’], [‘[email protected]’, ‘Mickey Mouse’], $content ); Be careful about using $ in your placeholders. Since it’s widely used in PHP, it’s not safe. It was the reason I’ve used mustache-like syntax in my example.

Insert page content into another page with a changed variable

Assuming you want to replace it with some static value (well, you can always change this anyway), some kind of find and replace snippet like this can do the trick: $content = apply_filters( ‘the_content’, $post->post_content); // set the replacement string value $replace = “REPLACEMENT”; // make sure the quotes used are exact $find_start = “<param … Read more

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