• Regular URLs of the pagination are like this – https://localhost/projects/page/2/
    But when i regenerate the pagination via wp_ajax (admin-ajax.php) pagination becomes a url var like this https://localhost/admin-ajax.php?pages=2, but i’ve managed to convert them into like this – https://localhost/projects?pages=2. Now wanted to know how can i make the urls just like permalink settings? Here is the code function in ajax function –

    
    	$query_args = array(
    		'post_type' => 'projects',
    		'paged' => $_POST['page'] + 1,
    		'post_status' => 'publish',
    		'posts_per_page' => 10
    	);
    
    	$the_query = new WP_Query( $query_args );
    
    	if(  $the_query->have_posts() ) :
    		ob_start();
    		while(  $the_query->have_posts() ):  $the_query->the_post();
    			include get_template_directory() . '/projects/html/project-card.php';
    		endwhile;
    		$projects = ob_get_contents();
    		ob_end_clean();
    
    		$pagination = wp_pagenavi(array('query' => $the_query, 'echo' => false));
    		$pagination = str_replace(admin_url( "admin-ajax.php" ), get_post_type_archive_link( 'projects' ), $pagination);
    	endif;
    
    	echo json_encode(
    			array(
    				'url' => $new_url,
    				'projects' => $projects,
    				'pagination' => $pagination
    			)
    		);
    	die;
    

    Thank you

    • This topic was modified 4 years, 10 months ago by zahedkamal87.
  • The topic ‘URL structure getting changed when generating the pagination via WP Admin Ajax’ is closed to new replies.