Tag Info

New answers tagged

0

thanks alot @Antonie Guillien, it solved :D var $j = jQuery; function testClick(){ alert('Button Clicked'); } $j(document).ready(function() { /*$j('.my-button').click(function(){ alert('Button Clicked'); })*/ })


0

The only way I could accomplish this is by using the wp_localize_script function. The function is quite straightforward and lets you simply send anything from server side to your script. This also outputs the variables inline, but this is the best WordPress allowd in this situation.


0

Try to apply some function like htmlspecialchars() on your query before searching for it, it will translate your special chars into HTML entities.


0

One thing you could do is set a variable in the archive.php like <script>var isArchive = true;</script>. Or in any template do if (is_archive()) { /* set the variable */ }. And then in the JS file do if (typeof isArchive != 'undefined') { } but there are probably way more elegant solutions that I'm unaware of. This also probably assumes you ...


0

This code worked for me in WordPress: add_filter( 'authenticate','one_session_per_user', 30, 3 ); function one_session_per_user( $user, $username, $password ) { $sessions = WP_Session_Tokens::get_instance( $user->ID ); $all_sessions = $sessions->get_all(); if ( count($all_sessions) ) { $login_page = home_url( ...


1

What a type you work with response If you work with json $.post( ajaxurl , data , function(res){ // your code },'json'); Remove wp_die() and replace with die()


0

To load your single.php template, first you need to move your functions.php code <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="entry-content"> <?php the_content(); ?> </div> ...


1

Your button was added dynamically. So you can not bind event in simple way. As button is added after DOM is fully ready. You need to bind it with the refrence of document or body jQuery(document).on('click', '#readmore', function(e){ e.preventDefault(); alert("you clicked the button"); jQuery("#bodytext").css("display", "block"); }); Read ...


0

You're not handling the names the same way as the other fields: //// VERIFIES CREDENTIALS $username = isset($_POST['username']) ? trim($_POST['username']) : ''; $first_name = isset($fields['user_first_name']) ? sanitize_text_field(trim($fields['user_first_name'])) : ''; $last_name = isset($fields['user_last_name']) ? ...


0

Ok, As it's front-end... I might: Set up the folder on the server so that WordPress can read/write (775 or 755 ordinarily works depending on how your server is configured in terms of user/group permissions). Allow a user on the front end to see the files or choose which file to delete Upon choosing the file, pass the parameter to an intermediary PHP ...


2

Your attempt to send your AJAX requests to wp-admin/admin-ajax.php is correct but it will be better to create a javascript global variable using wp_localize_script() to make any data available to your script in functions.php that you can normally only get from the server side of WordPress. For example, your javascript code can be in the same folder with ...


-1

You cannot use Ajax on Wordpress that way. There are many tutorial about using Ajax on wordpress. I think the simplest is http://natko.com/wordpress-ajax-login-without-a-plugin-the-right-way/


0

For anyone else with this problem that still can't get it working - check that your php function isn't returning before the die().


-1

You specify in the jquery API call that you expect to receive as a response a valid html, but the server returns simple text and not html, and this is probably the reason jquery decides that the request failed. Always look at the actual traffic with browser developer tool to debug whether ajax responses are being sent or not.


1

Shortcodes are too late to add ajax actions. Additionally, that actions would be added only if shortcode is executed, which is very unlikely to happen on a ajax request. The quickest way to make your code work is to move the add_action outside addimage() function. add_action( 'wp_ajax_wp_up', 'wp_up' ); add_action( 'wp_ajax_nopriv_wp_up', 'wp_up'); function ...


0

admin_url() should be used. However for some websites this request gives error 404 in front-end admin_url('wp-admin/admin-ajax.php') should point to an actual file (admin-ajax.php), as such WordPress won't pass it through index.php, and so it shouldn't lead to the theme's 404 page. (Unless the file has been deleted). ... unless you have a .htaccess ...


0

I had a similar problem. The code is good, but it needs to small modify to work. $args = array ( 'term' => $term_id, 'posts_per_page' => -1, 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'yourtaxonomyhere', 'field' => ...


0

Your first chunk of code is PHP, the second is javascript. Here is how a full example might look: In PHP (your theme's functions.php file or a plugin file): //First enqueue your javascript in WordPress function your_prefix_enqueue_scripts(){ //Enqueue your Javascript (this assumes your javascript file is located in your plugin in an "includes/js" ...


2

Use check_ajax_referer: https://codex.wordpress.org/Function_Reference/check_ajax_referer //Check nonce if ( !check_ajax_referer( 'nonce-action-name', '_wpnonce', false ) ){ echo __('Ajax Security Check', 'yourtextdomain'); die(); }


2

As for your PHP not being executed - the action parameter in your JavaScript AJAX call needs to match the hook name in your add_action call. Take a look at the example below. I haven't tested it but it should work. I have simplifed the AJAX call, feel free to modify it to suit your use case. var data = { action: 'jk-author-follow', // Look Ma' I talk to ...


1

There is a way out, use complete instead of success or done posts = $.ajax({ type: 'GET', url: ajaxurl, async: false, dataType: 'json', data: { action : 'getHotelsList' }, complete: function(results) { and try to remove async:false if problem persists


0

Use this code, hope it will help: wp_editor( '', 'custom_editor_id' ); \_WP_Editors::enqueue_scripts(); print_footer_scripts(); \_WP_Editors::editor_js(); More detail can be found here.


1

"How can I prevent unexpected output from reaching the browser/interfering with my AJAX response?" The Problem Something in your installation is generating "unexpected output," that is, it's creating content or data which should not be there if WordPress is running smoothly. This could imply a misconfigured server environment, a faulty WordPress ...


0

You'd need to put the variable's value onto the page so that javascript can pass it back to PHP using ajax. Ajax functions are a completely separate "page load" so even if you made it global it won't work. The best way to do this is using "wp_localize_script" (https://codex.wordpress.org/Function_Reference/wp_localize_script) Here's an full example of how ...


1

Don't even start. Ignoring official API is a no go, at best it will just creat headache for you and nasty surprise for the users when the plugin will fail when pinterest changes something and since it forces you to..... store user and password in a very unsecure way. This might be ok if your pugin is aimed to be run only for admins of non network wordpress ...


0

When I seemingly get nothing from an Ajax call I run Fiddler and examine the return when it comes to the request. The other day an Ajax call was failing inexplicably. Upon examining the return I saw another programmer was dumping an array into the output before I received my response. I never would have guessed that because the JavaScript never hit the ...


1

Your problem is probably because you do not return a json object but an html (actually mixed text and html), and you set jQuery to validate that the response is json, which it isn't. your code at the ajax handler should be something like $catshtml = wp_dropdown_categories(.....echo=0); $ret = array('data' => $catshtml); wp_send_json($ret); die(); on ...


0

Untested but ... You need to pass your "action" identifier with the data, like so: var data = { 'action': 'my_action', 'whatever': 1234 }; In your case, that action would be get_number_of_promos. The example is from the Codex page about AJAX, which you should read carefully: https://codex.wordpress.org/AJAX_in_Plugins


0

The jQuery .html and .load() is replacing the entire content. First, move your #Pagination outside of the ul.list-group. You will want this to continue to remain at the bottom of the list. Next, you will need to reconfigure your jQuery ajax to load the posts differently. You should load the posts from the next page, and append them to the list. Untested, ...



Top 50 recent answers are included