Friday, August 5, 2022
HomeWordPress Developmentphp - ajax pagination on customized put up sort - plugin improvement

php – ajax pagination on customized put up sort – plugin improvement


Pricey WordPress Developer,

I create desk of college, I am utilizing superior customized fields (ACF) plugins for inserting knowledge via admin web page.

I need to create ajax pagination utilizing plugin. I do know that there’s reply at this url:

Pagination Utilizing ajax

However, my case is customized put up sort. I’ve my very own college put up sort.

This my desk code:

 static operate displayAllUniversity(){

         
        ob_start();
        
        $allUniversity = new WP_QUERY(array(
            'posts_per_page' => -1,
            'post_type' => 'college'
        ));

        if($allUniversity->have_posts()){
            ?>
            <div class="container">
            <h1><?php echo $allUniversity->found_posts; ?> Daftar Universitas di Luar Negeri</h1>
            <desk>
                <tr>
                    <th class="tb-university-name">
                        <h2><sturdy>Nama Universitas</sturdy></h2>
                    </th>
                    <th class="tb-university-location">
                        <h2><sturdy>Lokasi Universitas</sturdy></h2>
                    </th>
                    <th class="tb-university-major">
                        <h2><sturdy>Jurusan Tersedia</sturdy></h2>
                    </th>
                    <th class="tb-university-scholarship">
                        <h2><sturdy>Beasiswa Tersedia</sturdy></h2>
                    </th>
                </tr>
            <?php
            whereas($allUniversity->have_posts()){
                $allUniversity->the_post();
                ?>
                <tr>
                    <th>
                        <div>
                        <?php 
                            $university_logo = get_field('university_logo');
                            $dimension="medium";
                            if( ! empty ( $university_logo ) ) {
                                echo wp_get_attachment_image($university_logo, $dimension, "", array( "class" => "img-responsive" ));
                            }
                        ?>
                        </div>
                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <particulars>
                            <abstract>lihat element &raquo;</abstract>
                            <p><?php echo wp_trim_words(get_the_content(), 15); ?><a href="<?php the_permalink(); ?>"> Baca Selengkapnya &raquo;</a></p>
                        </particulars>
                    </th>
                    <th>
                        <?php 
                        $university_locations = get_field('university_location');
                        if($university_locations): ?>
                        <ul>
                            <?php foreach($university_locations as $university_location): ?>
                                <li><h3><?php echo $university_location; ?></h3></li>
                            <?php endforeach; ?>
                        </ul>
                        <?php endif; ?>
                    </th>
                    <th>
                        <?php 
                        $university_majors = get_field('university_major');
                        if($university_majors):
                        ?>
                        <ul>
                            <?php foreach($university_majors as $university_major): ?>
                                <li><h3><?php echo $university_major; ?></h3></li>
                            <?php endforeach; ?>
                        </ul>
                        <?php endif; ?>
                    </th>
                    <th>
                        <?php 
                        
                        $university_scholarships = get_field('university_scholarship');
                        
                        if(rely((array)$university_scholarships) > 0):
                        ?>
                            <h3><a href="<?php the_permalink(); ?>"><?php echo rely($university_scholarships); ?> Beasiswa</a></h3>
                        <?php else: ?>
                            <h3><a href="<?php the_permalink(); ?>">0 Beasiswa</a></h3>
                        <?php endif; ?>
                    
                        
                    </th>
                </tr>
                <?php 
            }
            ?>
            </desk>
            </div>

            <?php
            
        }

        return ob_get_clean();

    }

I attempted to make use of this Pagination Utilizing ajax answer, utilizing this code:

static operate check(){

        $msg = '';

        if(isset($_POST['page'])){
            $web page = sanitize_text_field($_POST['page']);
            $cur_page = $web page;
            $web page -= 1;
            $per_page = 3;
            $previous_btn = true;
            $next_btn = true;
            $first_btn = true;
            $last_btn = true;
            $begin = $web page * $per_page;

            $all_blog_posts = new WP_Query(
                array(
                    'post_type'         => 'college',
                    'post_status '      => 'publish',
                    'orderby'           => 'post_date',
                    'order'             => 'DESC',
                    'posts_per_page'    => $per_page,
                    'offset'            => $begin
                )
            );
    
            $rely = new WP_Query(
                array(
                    'post_type'         => 'college',
                    'post_status '      => 'publish',
                    'posts_per_page'    => -1
                )
            );

            
            // Loop into all of the posts
            foreach($all_blog_posts as $key => $put up): 

                echo $post->post_title;

               
            endforeach;

        }


        
    }

Even the_title() nonetheless not exhibiting. What $_POST[“page”] variable anyway? is it nonetheless the identical if I exploit customized put up sort? Not $_POST[“university”] or one thing? I am actually confused.

Any reply is way appreciated, Thank You!

Finest Regards,

Hendra Sutrisno

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments