WordPress.org

Ready to get started?Download WordPress

Forums

get_pages returns no children in additional multi sites (1 post)

  1. duncmorley
    Member
    Posted 2 years ago #

    Hi there

    I am having a few issues with the get_pages function within a multisite set up.

    I have an dropdown that contains the parent pages. When a parent page is selected, it then gets a list of child pages via AJAX and displays them in a seperate dropdown.

    The function called by AJAX in my functions.php file is below.

    function implement_ajax() {
    	$id = $_POST['id'];
    	$product_selector = array(
    		'post_type'   => 'pcct_product',
    		'child_of'    => $id,
    		'sort_column' => 'menu_order'
    	);
    	$aPages = get_pages($product_selector);
    
    	echo '<option class="first-option" value="">Select Product</option>';
    
    	foreach ( $aPages as $pagg ) {
    		$option = '<option value="' . get_permalink( $pagg->ID ) . '">';
    		$option .= $pagg->post_title;
    		$option .= '</option>';
    		echo $option;
    	};
    	exit;
    };
    add_action('wp_ajax_my_special_ajax_call', 'implement_ajax');
    add_action('wp_ajax_nopriv_my_special_ajax_call', 'implement_ajax');

    When I tested this and put in an ID from a parent in the initial site, it returned the children from the parent from that site.

    As soon as I entered an ID from a parent page from the second site it returned no children at all.

    I think this is because get_pages is looking in the initial site for children of an ID that only exists in the second site.

    I'm sorry this is long winded, I hope i've explained it as best i can. Has anyone any suggestions of how to make get_pages search the correct site??

    Many thanks

Topic Closed

This topic has been closed to new replies.

About this Topic