jQuery .each to get post meta and subtract from a sum

You don’t need to use jQuery for something like this, it would be better done if you just use php! So if you store those 3 values in variables you can then do basic math with that data about output the results. while ($query->have_posts()) : $query->the_post(); $tourNum1 = get_post_meta($post->ID, ‘tour_details_number’, true); $tourNum2 = get_post_meta($post->ID, ‘tour_details_number2’, … Read more

Populating autocomplete field with custom post type

Your question is quite complicated, but lets give it a shot! I recently made a class that does just that that I am happy to share. It isn’t a complete response but will get you most of the way there. What you need to know is the quirky way WP does ajax, which involves registering … Read more

Confused about shortcode and settings values

As you can see in the Shortcode API, there is no jquery involved in evaluating shortcodes. Shortcodes are evaluated on the server side, in PHP, not on the client side with jquery. It is entirely up to you what you do with attributes in the shortcode. If the user writes something like: [demo speed=2000] you … Read more

Pass a php string to a javascript variable

You can use the wp_localize_script to pass a variable to your javascript. Here is an example: wp_register_script(‘your_script_name’, ‘path/to/script.js’); $variables = array ( ‘footer_caption’ => $attr[‘footer_caption’], ); wp_localize_script(‘your_script_name’, ‘js_object_name’, $variables ); wp_enqueue_script(‘your_script_name’); Then you can acces to this variable by: js_object_name.footer_caption

doing an ajax request always outputs 0

Your custom functions should always go in your theme’s functions.php file (if they are not within plugin territory). You should never try to modify any core files outside the wp-content folder (except wp-config.php) as they will be overridden by future updates. Now, there are 2 ways to do what you want. 1 – Admin-ajax This … Read more