2

I want to create a table show all post, I use WP_query to get all iformatio and create table template to list my post. But my problem is only one post inside the table.. I want to include all in table.

$wpb_all_query = new WP_Query(array('post_type'=>'vendor_management', 'post_status'=>'new', 'posts_per_page'=>-1)); ?>
    <?php if ( $wpb_all_query->have_posts() ) : ?>
<table class="responstable">
            <thead>
                <tr>
                    <th></th>
                    <th>Vendor Name</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
                    <td><input type="checkbox"/></td>
                    <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
                </tr>
            </tbody>
        </table>
    <?php endwhile; ?>
    <!-- end of the loop -->


    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Basically, I want to create like admin table in backend which is showing all post include edit, delete, bulk delete into front end, Can any body tell me to do it. I have try to use WP_List_Table but not working if in frond end.

0

I am not able to be exactly sure about your problem, maybe a live example may help. Also, do you have a custom post status "new" or its a typo?

but looking at the code, I see you have begun the table code outside the while loop, which is correct but ended it inside the loop. This might be the reason for only displaying 1 post. Please find the modified code.

$wpb_all_query = new WP_Query(array('post_type'=>'vendor_management', 'post_status'=>'new', 'posts_per_page'=>-1)); ?>
    <?php if ( $wpb_all_query->have_posts() ) : ?>
<table class="responstable">
            <thead>
                <tr>
                    <th></th>
                    <th>Vendor Name</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
                    <td><input type="checkbox"/></td>
                    <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
                </tr>

    <?php endwhile; ?>
     </tbody>
        </table>
    <!-- end of the loop -->
    <?php wp_reset_postdata(); ?>

<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Let me know if this works.

0

I have checked your issue I think this function will be working fine for you.Do check it and let me know if you face any issues into it.

$wpb_all_query = new WP_Query(array('post_type'=>'vendor_management', 'posts_per_page'=>-1)); ?>
    <?php if ( $wpb_all_query->have_posts() ) : ?>
<table class="responstable">
            <thead>
                <tr>
                    <th></th>
                    <th>Vendor Name</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
                    <td><input type="checkbox"/></td>
                    <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
                </tr>

    <?php endwhile; ?>
     </tbody>
        </table>
    <!-- end of the loop -->


<?php else : ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
 <?php wp_reset_postdata(); ?>

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.