New answers tagged

0

How can i return a PHP value from a WordPress page to a JQuery function? Use wp_localize_script to create an object and pass it to the JavaScript.


0

To verify nonces in Ajax requests, check_ajax_referrer() should be used instead of wp_verify_nonce(): Crete the nonce: $nonce = wp_create_nonce( 'vote-nonce-' . get_the_ID() ); Include it in JavaScript: jQuery(document).ready(function(){ jQuery(".post-voting").click(function(){ vote_nonce = <?php echo $nonce; ?> vote_id = jQuery(this)....


0

If you want to update title and description you should not use wp_update_attachment_metadata attachment title and description is not a meta it's a main post detail (attachment is custom post), you can do this with following code. $attachment = array( 'ID' => $id, 'post_title' => $title, 'post_content' => $description ); // now update main ...


0

I would suggest googling "wordpress ajax tutorials". Here is one that was beneficial to me. https://premium.wpmudev.org/blog/using-ajax-with-wordpress/ The first problem I see is you have not stated what your 'action' variable is. The JavaScript AJAX call specifies what function is targeted in the 'action' attribute. In WP, this is the hook executes your ...


0

This kind of questions is better asked on StackOverflow community. Maybe this JS hack would help: var elem = document.querySelector('.search-form input[name="search_keywords"]'); if ( null !== elem ) { elem.onchange = function() { var e = this , v = e.value; if ( ! v ) return; v = v.toString(); if ( 0 === v....


0

Since version 4.9 visual composer added shortcode lazy loading. To use VC shortcodes on AJAX content use this function before printing the content WPBMap::addAllMappedShortcodes();. So below code may help you, function get_page_content(){ $id = $_REQUEST['id']; $page_data = get_page($id); WPBMap::addAllMappedShortcodes(); echo ...


0

Ok, so after some fiddling, I've got things working. It turns out that I was setting the add_action hooks incorrectly for the AJAX part. The hooks need to be: add_action( 'wp_ajax_nopriv_MYFUNCTION', 'MYFUNCTION' ); and add_action( 'wp_ajax_MYFUNCTION', 'MYFUNCTION' ); ...in my case and original code the function ('MYFUNCTION') in question was to ...


0

Most of your question is off topic, I guess, because it involves a question about Google's APIs. You would need three things: Create the possibility to login to your site with a Google account. There are plugins that make this possible, like this one. Import the list of group members from Google. There probably is an API for this, but that is out of the ...


0

My philosophy is that if you use a system like WP then you embrace it and do things the WP way. WP has plenty of hooks that let you override functionality and the flexible theme structure gives you almost total control over the output. So, I'd advise using a WP theme and WP built in menus. Your menu items will link to normal WP pages. The site will work ...


1

Please do not put this code into production OK. So there are many things wrong with the code that need fixing before we can even begin to answer your question. Firstly we're using $_REQUEST without good reason -- $_REQUEST gives us access to all of the information sent in the request, which means that $_POST['foo'] $_REQUEST['foo'] === $_GET['foo'] and ...


0

I can't comment on the validity of the AJAX call; it's a different style than I have used -- but inside the click(function(e) { code, you might try trapping the default page action to prevent it from triggering the page refresh: $("#myelement).click(function(e){ e.preventDefault();


0

Since the file you send is base64 encoded, you will need to decode and save the result into a file at a temp directory. From there it is just a normal server side wordpress image manipulation and insertion of the relevant info into the DB, something that there are many examples for on this site. You should probably return the URL of the generated image in ...


1

To use AJAX in a WordPress website you can the admin-ajax.php file. This file handles your requests and sends it to the correct function. A short step-by-step guide on how to achieve: First you need to localize your javascript file so that it knows the URL of the admin-ajax.php file on your server. add_action( 'wp_enqueue_scripts', 'wpse_229573_localize' )...


0

You have to use $_REQUEST instead of $_POST in PHP: function rnr_contact_callback() { $name = $_REQUEST['firstName'] . ' ' . $_REQUEST['lastName']; wp_mail( 'myname@gmail.com', 'Contact form submitted', $name . '(' . $_REQUEST['email'] . ') sent a message: ' . $_POST['comment'] ); exit; }


0

You second JS setting is more in the right direction, your biggest failure seems in misunderstanding how ajax requests are handled on the WP PHP/server side. On the PHP side, an action is being triggered based on the action parameter in your AJAX request. Since this is a generic mechanism it doesn't have any facilities to "guess" how many parameters are ...


0

You can parse the data value to a variable ($formdata) then can access the data you like as: parse_str( $_POST[ 'data' ], $formdata ); $category = $formdata[ 'category' ];


0

First the way to do this is with a form using the post method, it is slightly easier to understand: <!-- form with AJAX action and iframe target --> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" target="emailsendframe"> <!-- AJAX action field to trigger function--> <input type="hidden" name="action" value=...


-1

If what you want is is a full page refresh then you don't need ajax at all and inserting the htt-equip html meta will do the trick <meta http-equiv="refresh" content="5" > (content is time in seconds IIRC) You just hook on wp_head and insert it. function wpse_228671_wp_head() { echo '<meta http-equiv="refresh" content="5" >'; } add_action('...


1

I've read through your post in it's entirety, I certainly don't see anything particularly wrong with it, but it sounds to me like your more frustrated with how it's been laid out. I personally have a big objected oriented programming background, it allows me to establish a structure and makes my code much more re-usable. My suggestion to you would be to ...


0

$.ajax is very simple and you can append more parameters easily in the data: {action:'my_test_ajax'} line, try this: var target = 'http://' + window.location.hostname + '/wp-admin/admin-ajax.php'; $.ajax({ url: ajax, data: {action:'my_test_ajax'}, type: 'post', success: function(data){ console.log(data, data.title, data.content) ...


1

I couldn't find any WP specific event to hook in to. What you can do is set up an observer with a callback to respond to DOM changes using MutationObserver and check if the your featured image has been added in the callback. There's no support in IE < 11 though, which may be a deal breaker for you, or maybe not. I've done minimal testing on this, but it ...


0

I believe the problem is you are not calling do_shortcode() in the output buffer. You don't need to be running the loop within the output buffer since I can assume get_content_template() simply returns HTML with embedded shortcodes. Save that to a string variable, then run that through the do_shortcode() and save the echoed output to the buffer. This is ...


1

Very broad solution. There are two problems you are facing there are different HTML generated by the server based on if there is a featured image Meta box are just a UI artifact of post editing and are not easily manipulated via AJAX (even in AJAX it is easier to handle full objects rather then their individual properties, even if only for keeping ...



Top 50 recent answers are included