Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking to create a button on a parent level page. If you click that button it runs through each of its children and performs some action via Ajax. The output is spit out back to the parent level page.

I assign each page in wp_list_pages a unique ID in a custom walker and I pass a bunch of variables I need for my JavaScript.

<a id="review_hyperlink-' . $post_id . '" href="#" 
        data-owner_id="' . $this->current_user->ID . '"
        data-post_id="' . $post_id . '" 
        data-has_owners="' . $this->owned_by_this_user . '" 
        >' . $this->review_status . '</a></div>';

My JavaScript then starts off as:

jQuery(document).ready(function($){
$('a[id^="review_hyperlink-"]').click(function() {
    var this_link = $(this);

And my output is:

$.get(ajaxurl, post_data, function(response) {
        $(this_link).html(response).removeAttr("href");

This works fine but I want to have the same output shown on every child of the parent. I'm wondering what the best way to approach this is. If my page depth was 1, I could simply assign a unique class to a page's children. But because it's 3 or 4 children deep, I need to be able to only call on the children of what parent I click. Example, if I click on a parent that is 2 layers deep, I don't want to assign the same class to it's parent.

Any help is much appreciated. Thanks!

EDIT

I changed my ajax response to this:

$.get(av_review_vars.ajaxurl, post_data, function(response) {
        $(this_link).html(response).removeAttr("href");
        $(this_link).find('a[id^="review_this_post-"]').html(response).removeAttr("href");
    });

But I'm still not getting any output from the children pages even though they have a link with an id attr of 'review_this_post-post_id'. Any advice?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.