Monday, August 15, 2022
HomeWordPress Developmentwp admin - Learn how to filter with dropdown in backend for...

wp admin – Learn how to filter with dropdown in backend for customized knowledge


I’ve a customized desk (Desk Title: ssl_transaction_cus) within the database which is used for storing donation info. I fetched all of information from this desk in ‘admin menu web page’ with a desk(With Desk tag). I would really like to have the ability to filter these knowledge in line with ‘Occasion Title’.

I’m making an attempt to in line with this reply . However, there are code for customized publish or publish. However, I’ve no CPT for these knowledge, simply customized knowledge. I’m making an attempt for very long time. However couldn’t success.

enter image description here

Right here is my code for fetching knowledge.

perform my_menu_donation_new() {
add_menu_page('Transaction-donation-page-main', 'Handle Transaction (Donation)', 'manage_options', 'transaction-donation-menu', 'my_options_doanation_new');
  perform my_options_doanation_new(){

      international $wpdb;
      $end result = $wpdb->get_results( "SELECT * FROM ssl_transaction_cus_donate");  

      echo"<div><h1>Transaction for Donation</h1><desk class="quote" fashion="border: 1px stable #014d6d; width:100%">";
      echo"<tr><th fashion="border:1px stable #014d6d;">Sl.</th><th fashion="border:1px stable #014d6d;">Title</th><th fashion="border:1px stable #014d6d;">E mail</th><th fashion="border:1px stable #014d6d;">Telephone No</th><th fashion="border:1px stable #014d6d;">Occasion Title</th><th fashion="border:1px stable #014d6d;">Trans. Date</th><th fashion="border:1px stable #014d6d;">Trans. Id</th><th fashion="border:1px stable #014d6d;">Quantity</th><th fashion="border:1px stable #014d6d;">Card Kind</th></tr>";
    
      $i=1;
      foreach ( $end result as $res ) {
          echo "<tr fashion="border:1px stable #014d6d;">";
          echo "<td>".$i."</td>"."<td>".$res->Title."</td>"."<td>".$res->E mail."</td>"."<td>".$res->PhoneNo."</td>"."<td>".$res->EventName."</td>"."<td>".$res->TransactionDate."</td>"."<td>".$res->TransactionId."</td>"."<td>".$res->Quantity."</td>"."<td>".$res->CardType."</td>";

          echo "</tr>";
          $i++;
          }       
      echo"<tr><th fashion="border:1px stable #014d6d;">Sl.</th><th fashion="border:1px stable #014d6d;">Title</th><th fashion="border:1px stable #014d6d;">E mail</th><th fashion="border:1px stable #014d6d;">Telephone No</th><th fashion="border:1px stable #014d6d;">Occasion Title</th><th fashion="border:1px stable #014d6d;">Trans. Date</th><th fashion="border:1px stable #014d6d;">Trans. Id</th><th fashion="border:1px stable #014d6d;">Quantity</th><th fashion="border:1px stable #014d6d;">Card Kind</th></tr>";
      echo "</desk></div>";
      }

}

add_action(‘admin_menu’, ‘my_menu_donation_new’);

And right here is the code for filtering. I am positive I wrote the improper code. Can anyone assist me? Thanks.

add_action( 'restrict_manage_posts', perform(){
     international $wpdb, $pagenow;
     
         $values = array();
         $EventNameQuery = $wpdb->get_results("SELECT EventName from ssl_transaction_cus");

          foreach ($EventNameQuery as &$knowledge){
             $values[$data->EventName] = $data->EventName;
          }
        
         ?> <choose identify="admin_event_name">
                <choice worth="">Occasion Title</choice>

                <?php 
                $current_v = isset($_GET['admin_event_name'])? $_GET['admin_event_name'] : '';
                foreach ($values as $label => $worth) {
                    printf(
                        '<choice worth="%s"%s>%s</choice>',
                        $worth,
                        $worth == $current_v? ' chosen="chosen"':'',
                        $label
                    );
                }
                ?>
            </choose>
         <?php
     
 }); 
 
 add_filter( 'parse_query', perform($question){
     international $pagenow;
     if ($pagenow=='admin.php?web page=transaction-donation-menu' && isset($_GET['admin_event_name']) && !empty($_GET['admin_event_name'])) {
     }
 }); 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments