How To Edit And Delete In Wordpress By Passing Id?

php wordpress

60 观看

1回复

22 作者的声誉

I have Page Template-ViewAll to display all Records From Database in wordpress Page named DisplayAll in which i have used page template -ViewAll.I Have Attached My code Here.Now I Want To Edit And Delete Records.How To do That with Custom Page Templates For Both In Wordpress By Passing Id For it in wordpress?

<?php
/**
 * Template Name:ViewAll
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0

 */

get_header(); ?>

<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php
            $newdb=new wpdb('root','','wpdemo1','localhost');



            $rows=$newdb->get_results("Select * From wp_student");
            if($rows)
            {
                foreach ($rows as $obj) 
                {
                    //$path = 'admin.php?page=EditStud&id='.$obj->roll;
                    //$url = admin_url($path);
                    //$id=$obj->roll;
                   ?>
                    <table>

                    <tr>
                     <td><?php echo $obj->roll;?></td>
                     <td><?php echo $obj->name;?></td>
                     <td><?php echo $obj->dept;?></td>

                     <td><a href=""> Delete </a></td>
                     <!--<td><a href="<?php  //admin_url( '/wp-admin/admin.php?page=editstud&edit-id=' . $obj->roll ); ?>">Edit</a></td>-->
                    <td><a href="">Edit</a></td>

                    <!--<td><a href="http://localhost/wptest1/index.php/editstud/?id=<?php //echo  $obj->roll;?>"> Edit </a></td>-->
                    </tr>
                    </table>
                    <?php
                }
            }
            /*while ( have_posts() ) : the_post();

                get_template_part( 'template-parts/page/content', 'page' );

                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;

            endwhile; */// End of the loop.
            ?>

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer();
作者: Yashpal Modi 的来源 发布者: 2017 年 9 月 15 日

回应 1


0

52 作者的声誉

决定

Are you asking for this ??

<a href = "<?php echo  get_template_directory_uri(); ?>/editstud.php?edit-id=<?php echo $obj->roll;?> ">Edit </a>

This works if you create custom page in the theme main directory.

作者: Najeeb Zulfiqar 发布者: 2017 年 9 月 15 日
32x32