0

I have a page where users filter results from the Ultimate WP Query Search Filter plugin. The results are shown in a DIV via an AJAX call. This is working 100%. However I have another AJAX function attached to each result in the query allowing users to create a new post from search results.

(See this post for how I got that to work Create new Wordpress post [wp_insert_post] based on results of a WP_Query)

The problem I am having now is that when I view the wp_query results - I have a button on each record to "Add" to. When I trigger the button on the first item it works 100%. However when I click on any of the subsequent items - it still creates the post, but ignores all the values attached to it.

I am guessing I need to reset the AJAX function after each call, but unsure how to do that?

Here is the code for adding the posts: https://gist.github.com/stankobrin/4d15c29024e306b2ea43 Here is the JS / AJAX code: https://gist.github.com/stankobrin/61843fefef464e8778a3

Any help on this would be appreciated - I have spent countless hours trying everything!

S

1

The problem is with the element id you are taking.

Because if page has multiple ids with the same name (e.g apftitle). Then it will work for the first element only because it search for the first occurrence of id and work for it only

  1. You can solve it by keeping the ids dynamic so it will work for all.
  2. Or you can use the javascript's this pointer which refers to the current element with which it is attached.
  • thanks for quick feedback - excuse the ignorance, but how would I make the ID's dynamic? – stankobrin Aug 5 '14 at 6:26
  • I havent't gone through you whole code. Can tell if you can post what is the response returned by ajax that you append in <div> with "apf-response" id. – TBI Infotech Aug 5 '14 at 6:33
  • unfortunately the apf-response only fires on the first item too. Any help implementing this would be hugely appreciated. I have tried adding a dynamic ID to the form and the add button - but same result. Only works off the first item and not the rest – stankobrin Aug 6 '14 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.