Lesson 30 Implementation: Adding Bulk Delete Functionality to the Flipnzee Auctions Plugin

In Lesson 29, we added checkboxes and a Bulk Actions dropdown to the auction management table. Although the interface looked complete, selecting auctions and clicking Apply did not actually perform any action.

In this implementation, we’ll connect the user interface to the database so administrators can securely delete multiple auction records with a single click.


Step 1: Create a Method to Delete Multiple Auctions

The first task was to create a reusable method responsible for deleting multiple auction records from the database.

Inside includes/class-auction-manager.php, a new method named delete_multiple_auctions() was added.

public static function delete_multiple_auctions( $auction_ids ) {

	global $wpdb;

	$table = $wpdb->prefix . 'flipnzee_auctions';

	foreach ( $auction_ids as $auction_id ) {

		$wpdb->delete(
			$table,
			array(
				'id' => absint( $auction_id ),
			),
			array( '%d' )
		);
	}
}

Each submitted auction ID is sanitized using absint() before being passed to $wpdb->delete(), ensuring only valid numeric IDs are processed.


Step 2: Register a Bulk Action Processor

Next, the plugin needed a way to detect when an administrator clicks the Apply button.

Inside the constructor of admin/class-admin.php, a new action hook was registered.

add_action(
	'admin_init',
	array( $this, 'process_bulk_actions' )
);

The admin_init hook executes during every admin request, making it an ideal place to process submitted bulk actions before the page is rendered.


Step 3: Create the Bulk Action Handler

A new method named process_bulk_actions() was then added to the admin class.

The method performs several validation checks before deleting any records.

It verifies:

  • The current user has permission to manage auctions.
  • A bulk action has actually been submitted.
  • The selected action is Delete.
  • At least one auction has been selected.

If any of these conditions fail, the method immediately exits without making changes.


Step 4: Protect the Request with a WordPress Nonce

Security is an essential part of WordPress plugin development.

A nonce field was added to the bulk action form.

wp_nonce_field(
	'flipnzee_bulk_delete',
	'flipnzee_bulk_nonce'
);

This hidden field generates a unique security token that WordPress can later verify.


Step 5: Verify the Nonce

Inside process_bulk_actions(), the submitted nonce is validated before processing any deletion.

if (
	! isset( $_POST['flipnzee_bulk_nonce'] ) ||
	! wp_verify_nonce(
		sanitize_text_field(
			wp_unslash( $_POST['flipnzee_bulk_nonce'] )
		),
		'flipnzee_bulk_delete'
	)
) {
	return;
}

This prevents Cross-Site Request Forgery (CSRF) attacks by ensuring the request originated from the plugin’s own administration page.


Step 6: Retrieve the Selected Auction IDs

The selected auction IDs are submitted as an array.

Each value is sanitized before use.

$auction_ids = array_map(
	'absint',
	wp_unslash( $_POST['auction_ids'] )
);

Using array_map() ensures every submitted value becomes a valid integer.


Step 7: Delete the Selected Auctions

After validation, the manager method is called.

Flipnzee_Auction_Manager::delete_multiple_auctions(
	$auction_ids
);

This loops through every selected auction and removes it from the custom database table.


Step 8: Redirect Back to the Auction List

After completing the deletion, the administrator is redirected back to the auction listing page.

wp_safe_redirect(
	admin_url(
		'admin.php?page=flipnzee-all-auctions&message=deleted'
	)
);

exit;

Using wp_safe_redirect() prevents accidental duplicate submissions if the page is refreshed.


Step 9: Display a Success Message

The existing success notification on the All Auctions page automatically detects the message=deleted query parameter and displays a confirmation message.

Auction deleted successfully.

This provides immediate feedback that the operation completed successfully.


Step 10: Test the Feature

After rebuilding and uploading the plugin, the feature was tested by:

  1. Selecting multiple auctions.
  2. Choosing Delete from the Bulk Actions dropdown.
  3. Clicking Apply.
  4. Confirming that the selected auctions disappeared.
  5. Verifying that the success message appeared.

The implementation worked exactly as expected.


Final Result

The auction management screen now supports professional bulk operations similar to WordPress core.

Administrators can:

  • Select one or many auctions.
  • Delete multiple records with a single action.
  • Receive immediate confirmation after deletion.
  • Benefit from WordPress nonce protection against unauthorized requests.

Combined with pagination, searching, sorting, and row actions implemented in previous lessons, the auction management screen now offers a polished administrative experience.


What We Learned

By completing this implementation, we learned how to:

  • Create reusable database methods for bulk operations.
  • Process submitted bulk actions in the WordPress admin area.
  • Register custom admin hooks.
  • Secure forms using WordPress nonces.
  • Sanitize arrays of submitted IDs.
  • Delete multiple database records safely.
  • Redirect after processing to prevent duplicate submissions.
  • Display success notifications following bulk operations.

With bulk deletion complete, the Flipnzee Auctions plugin now includes one of the most commonly used productivity features found in professional WordPress plugins.

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:

 

Lesson 29 Implementation: Bulk Actions with WP_List_Table

Implementation Walkthrough

In this lesson, the goal was to allow administrators to select multiple auctions at once using checkboxes and prepare the table for bulk operations such as deleting multiple auctions simultaneously. WordPress provides built-in support for bulk actions in WP_List_Table, making this feature straightforward to implement.

Step 1: Add a Checkbox Column

The first step was to add a new checkbox column to the table.

Inside the get_columns() method of admin/class-auctions-table.php, a new column named cb was added as the first column.

public function get_columns() {

	return array(
		'cb'             => '<input type="checkbox" />',
		'id'             => 'ID',
		'listing_id'     => 'Listing ID',
		'start_price'    => 'Start Price',
		'reserve_price'  => 'Reserve Price',
		'buy_now_price'  => 'Buy Now Price',
		'status'         => 'Status',
		'created_at'     => 'Created At',
	);
}

The header checkbox allows administrators to quickly select or deselect every row displayed on the current page.


Step 2: Register the Bulk Actions

Next, the available bulk actions were registered by creating the get_bulk_actions() method.

public function get_bulk_actions() {

	return array(
		'delete' => 'Delete',
	);
}

At this stage only one action—Delete—was added, but additional actions such as Activate, Close Auction, or Export could easily be added later.


Step 3: Display a Checkbox for Every Auction

After registering the bulk actions, a new column_cb() method was added.

public function column_cb( $item ) {

	return sprintf(
		'<input type="checkbox" name="auction_ids[]" value="%d" />',
		absint( $item->id )
	);
}

This method tells WP_List_Table how to render the checkbox for each auction row.

Each checkbox stores the auction’s database ID, making it available when the administrator submits the bulk action form.


Step 4: Verify the Table Still Works

Before uploading the plugin, the PHP syntax was checked.

php -l admin/class-auctions-table.php

The output confirmed that no syntax errors existed.


Step 5: Upload the Updated Plugin

The plugin ZIP was rebuilt and uploaded to WordPress.

After activation, the All Auctions page immediately displayed:

  • A checkbox beside every auction
  • A “Select All” checkbox in the table header
  • A Bulk Actions dropdown
  • An Apply button

At this stage the Delete action did not yet perform any operation—it simply prepared the interface for the next lesson.


Result

The auction management screen now behaves much more like WordPress’ built-in Posts, Pages, and Media screens.

Administrators can:

  • Select one auction
  • Select multiple auctions
  • Select all auctions on the current page
  • Choose a bulk action from the dropdown
  • Prepare to process multiple records with a single click

Although the Delete option is not functional yet, the user interface is now fully prepared for implementing bulk deletion in the next lesson.


What We Learned

By completing this lesson, we learned how to:

  • Add a checkbox column to a WP_List_Table
  • Register custom bulk actions
  • Create row checkboxes with column_cb()
  • Integrate WordPress’ built-in Bulk Actions dropdown
  • Prepare an admin table for processing multiple records efficiently

With this foundation in place, the next lesson will focus on processing the selected auctions and implementing a secure Bulk Delete feature using WordPress nonces and best practices.

Download Source Code

Download the starting version of the plugin before the lesson:

Download the completed version after this lesson:

Lesson 29 — Adding Bulk Delete to the Auctions Table Using WP_List_Table


Introduction

As the number of auctions grows, deleting them one at a time becomes inefficient. WordPress solves this problem by allowing administrators to select multiple rows and perform an action on all of them simultaneously.

In this lesson, we’ll add Bulk Delete to our custom WP_List_Table. Administrators will be able to select multiple auctions using checkboxes and delete them all with a single action, just like on the Posts or Pages screens.

By the end of this lesson, your Auctions table will feel even more like a native WordPress admin screen.


What You Will Learn

In this lesson, you will learn how to:

  • Add a checkbox column to WP_List_Table
  • Display a checkbox for each auction
  • Register bulk actions
  • Detect which bulk action the user selected
  • Process multiple selected auctions
  • Secure the operation using WordPress nonces
  • Display a success message after bulk deletion

Why Bulk Actions Matter

Imagine managing hundreds of auctions.

Deleting them individually would require:

  • Click Delete
  • Confirm deletion
  • Wait for the page to reload
  • Repeat the process dozens of times

Bulk actions allow administrators to remove many auctions in a single operation, improving productivity and creating a much better user experience.


Files We Will Modify

During this lesson, we will update:

admin/class-auctions-table.php

and

admin/class-admin-posts.php

We will also make a small update to:

admin/class-admin.php

to display an appropriate success notice after the bulk action completes.


New WordPress Concepts

This lesson introduces several important WP_List_Table methods:

  • column_cb()
  • get_bulk_actions()
  • process_bulk_action()
  • current_action()

These methods are used by many WordPress core administration screens.


Expected Result

After completing this lesson, the Auctions table will include:

  • A checkbox beside every auction
  • A “Select All” checkbox in the table header
  • A Bulk Actions dropdown
  • A Delete option
  • A single-click way to delete multiple auctions

The feature will closely resemble the familiar bulk actions available on the WordPress Posts screen.


Before You Start

Make sure your plugin already includes:

  • ✅ Working Add Auction page
  • ✅ Edit Auction page
  • ✅ Delete Auction action
  • ✅ Pagination
  • ✅ Search
  • ✅ Sortable columns

These features were implemented in the previous lessons and will be used throughout this exercise.


What Comes Next

In the implementation article, we’ll build this feature step by step by:

  1. Adding the checkbox column.
  2. Creating the Bulk Actions dropdown.
  3. Processing selected auctions.
  4. Deleting multiple records safely.
  5. Displaying a success message after completion.
  6. Testing the feature thoroughly.

Implementing Lesson 28 — Adding Sortable Columns to the Auctions Table (Step by Step)


Difficulty: Intermediate
Project: Flipnzee Auctions Plugin
Lesson Implemented: Lesson 28


Introduction

In the previous lessons, we transformed our custom Auctions page into a professional WordPress administration screen by adding pagination and search functionality.

Although administrators could now search for auctions, they still could not sort the table by different columns. WordPress users expect to be able to click column headings like ID, Start Price, or Created At to sort data.

In this implementation, we enhanced our custom WP_List_Table by making its columns sortable.


Step 1 — Define the Sortable Columns

The first step was to tell WordPress which columns should be sortable.

Inside:

admin/class-auctions-table.php

we added a new method:

public function get_sortable_columns() {

	return array(
		'id'            => array( 'id', true ),
		'listing_id'    => array( 'listing_id', false ),
		'start_price'   => array( 'start_price', false ),
		'reserve_price' => array( 'reserve_price', false ),
		'buy_now_price' => array( 'buy_now_price', false ),
		'status'        => array( 'status', false ),
		'created_at'    => array( 'created_at', false ),
	);
}

Each array entry tells WordPress which database column should be used for sorting.


Step 2 — Enable Sorting in prepare_items()

Defining sortable columns alone is not enough.

Inside prepare_items(), we updated the column headers:

From:

$this->_column_headers = array(
	$this->get_columns(),
	array(),
	array(),
);

To:

$this->_column_headers = array(
	$this->get_columns(),
	array(),
	$this->get_sortable_columns(),
);

This small change tells WP_List_Table to convert the column headings into clickable links.


Step 3 — Read Sorting Parameters

Next, we needed to determine which column the administrator clicked.

Inside prepare_items(), we added:

$orderby = isset( $_GET['orderby'] )
	? sanitize_key(
		wp_unslash( $_GET['orderby'] )
	)
	: 'created_at';

$order = isset( $_GET['order'] )
	? strtoupper(
		sanitize_text_field(
			wp_unslash( $_GET['order'] )
		)
	)
	: 'DESC';

Why?

When a user clicks a sortable column, WordPress automatically appends parameters such as:

orderby=start_price
order=ASC

We safely read these values before using them.


Step 4 — Pass Sorting Information to the Database Layer

Previously, our manager class received only:

  • page size
  • offset
  • search term

We extended the call to include:

Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset,
	$search,
	$orderby,
	$order
);

Now the database query knows exactly how to sort the results.


Step 5 — Update the Manager Method

Inside:

includes/class-auction-manager.php

we modified the method signature:

public static function get_all_auctions(
	$per_page = 20,
	$offset = 0,
	$search = '',
	$orderby = 'created_at',
	$order = 'DESC'
)

This allows sorting preferences to be passed from the table class.


Step 6 — Validate the Column Name

Unlike values, SQL column names cannot be protected using prepared statements.

Instead, we created a whitelist:

$allowed_columns = array(
	'id',
	'listing_id',
	'start_price',
	'reserve_price',
	'buy_now_price',
	'status',
	'created_at',
);

We then verified the requested column:

if ( ! in_array( $orderby, $allowed_columns, true ) ) {
	$orderby = 'created_at';
}

This prevents invalid or malicious column names from being used.


Step 7 — Validate the Sort Direction

We also limited the sort direction:

$order = ( 'ASC' === strtoupper( $order ) )
	? 'ASC'
	: 'DESC';

Only two values are accepted:

  • ASC
  • DESC

Anything else automatically falls back to descending order.


Step 8 — Update the SQL Query

Previously, every query ended with:

ORDER BY created_at DESC

We replaced it with:

ORDER BY {$orderby} {$order}

Both the search query and the default query were updated so that sorting works in every situation.


Step 9 — Test the Feature

After uploading the updated plugin, we verified that:

  • ID became clickable
  • Listing ID became clickable
  • Start Price became clickable
  • Reserve Price became clickable
  • Buy Now Price became clickable
  • Status became clickable
  • Created At became clickable

Clicking a column heading automatically updated the URL and changed the sort order.


Challenges Encountered

This lesson involved several small debugging tasks before everything worked correctly.

Some of the issues included:

  • Accidentally duplicating the search query inside get_all_auctions().
  • Forgetting to replace ORDER BY created_at DESC with the dynamic sorting variables.
  • Leaving the third element of _column_headers empty, which prevented WordPress from displaying clickable column headings.

By resolving these issues one by one, the sortable table behaved exactly as expected.


What We Learned

This implementation introduced several important WordPress concepts:

  • Using get_sortable_columns()
  • Registering sortable columns with WP_List_Table
  • Reading URL parameters safely
  • Passing sorting information between classes
  • Validating SQL identifiers using a whitelist
  • Restricting sort directions
  • Building flexible SQL queries while maintaining security

These are common techniques used in professional WordPress plugins that display tabular data.


Final Result

After completing this implementation, the Flipnzee Auctions plugin now provides a much more user-friendly administration interface.

Administrators can click any supported column heading to reorder the table, making it easier to analyse auction data and locate important records.

Combined with the search and pagination features implemented in earlier lessons, the Auctions page now closely resembles the polished interfaces found throughout the WordPress admin dashboard.


Download Source Code

Download the starting version of the plugin before implementing sortable columns:

Download the completed version containing fully functional sortable columns:

Lesson 28 — Adding Sortable Columns to the Auctions Table Using WP_List_Table

Series: Building the Flipnzee Auctions WordPress Plugin
Lesson: 28
Difficulty: Intermediate


Introduction

In the previous lessons, we transformed our Auctions table into a professional management interface by adding pagination and functional search.

However, one important feature is still missing.

When managing many auctions, administrators often want to sort records by clicking column headings, just like they can on the WordPress Posts, Pages, Users, and Comments screens.

In this lesson, we’ll add sortable columns to our custom WP_List_Table, allowing administrators to sort auctions with a single click.


What You’ll Learn

By the end of this lesson, you’ll know how to:

  • Register sortable columns in WP_List_Table
  • Detect the selected sort column
  • Detect ascending and descending order
  • Build secure dynamic SQL queries
  • Keep sorting compatible with pagination and search
  • Create a much more professional admin interface

Why Sortable Columns Matter

Imagine managing hundreds of auctions.

Sometimes you may want to:

  • View the newest auctions first
  • Sort by Listing ID
  • Find the highest Buy Now price
  • Group auctions by Status
  • Review the lowest Start Price

Without sortable columns, administrators must manually search through multiple pages.

Sorting makes large datasets much easier to manage.


How WordPress Sorting Works

When a column header is clicked, WordPress automatically appends two URL parameters.

Example:

admin.php?page=flipnzee-all-auctions&orderby=start_price&order=asc

or

admin.php?page=flipnzee-all-auctions&orderby=status&order=desc

Your plugin simply needs to read these values and use them safely.


Step 1 — Register Sortable Columns

Inside your table class, implement:

public function get_sortable_columns() {

	return array(
		'id'            => array( 'id', true ),
		'listing_id'    => array( 'listing_id', false ),
		'start_price'   => array( 'start_price', false ),
		'reserve_price' => array( 'reserve_price', false ),
		'buy_now_price' => array( 'buy_now_price', false ),
		'status'        => array( 'status', false ),
		'created_at'    => array( 'created_at', false ),
	);
}

This tells WordPress which columns are sortable.


Step 2 — Read Sorting Parameters

Inside prepare_items(), retrieve the selected column:

$orderby = isset( $_GET['orderby'] )
	? sanitize_key( $_GET['orderby'] )
	: 'created_at';

Next, retrieve the direction:

$order = isset( $_GET['order'] )
	? strtoupper(
		sanitize_text_field(
			wp_unslash( $_GET['order'] )
		)
	)
	: 'DESC';

Step 3 — Whitelist Allowed Columns

Never trust user input directly.

Instead, create an allowed list:

$allowed = array(
	'id',
	'listing_id',
	'start_price',
	'reserve_price',
	'buy_now_price',
	'status',
	'created_at',
);

If an invalid column is supplied, fall back to:

created_at

This prevents SQL injection.


Step 4 — Update the Database Query

Modify the Auction Manager so get_all_auctions() also accepts:

$orderby

and

$order

The SQL becomes:

ORDER BY created_at DESC

or

ORDER BY start_price ASC

depending on the administrator’s selection.


Step 5 — Keep Search and Pagination Working

Sorting should work together with:

  • Search
  • Pagination

All three features should operate simultaneously.

For example:

  • Search for draft
  • Sort by Start Price
  • Navigate to Page 2

Everything should continue working correctly.


Step 6 — Test Every Column

Click each heading:

  • ID
  • Listing ID
  • Start Price
  • Reserve Price
  • Buy Now Price
  • Status
  • Created At

Verify that clicking once sorts ascending.

Clicking again sorts descending.


Security Considerations

Because column names cannot be parameterized using $wpdb->prepare(), always whitelist allowed columns before inserting them into SQL.

Never allow arbitrary column names supplied by users.

Continue sanitizing all URL parameters using:

  • sanitize_key()
  • sanitize_text_field()
  • wp_unslash()

This keeps the plugin secure while supporting dynamic sorting.


Expected Result

After completing this lesson, administrators will be able to:

  • ✅ Click any supported column heading
  • ✅ Sort ascending or descending
  • ✅ Combine sorting with searching
  • ✅ Combine sorting with pagination
  • ✅ Manage auctions much more efficiently

The Auctions page will now behave almost identically to the native WordPress administration tables.


Conclusion

Adding sortable columns is another significant milestone in the development of the Flipnzee Auctions plugin.

Together with pagination and search, this feature creates a much richer administration experience and brings the plugin closer to production quality.

At this stage, the Auctions table supports the three most important data management features expected in professional WordPress plugins.


In the Next Lesson

We’ll implement bulk actions, allowing administrators to select multiple auctions using checkboxes and perform operations such as:

  • Delete Selected Auctions
  • Activate Multiple Auctions
  • Close Multiple Auctions

Bulk actions are one of the final major features needed before the Auctions management screen reaches enterprise-level usability.

Lesson 27 — Implementing Functional Search in a Custom WP_List_Table

Series: Building the Flipnzee Auctions WordPress Plugin
Lesson: 27
Difficulty: Intermediate


Introduction

In Lesson 26, we successfully added a professional search box above the auctions table. Although the interface looked complete, typing a search term did not actually filter the records.

In this lesson, we’ll connect the search box to the database so administrators can search auctions directly from the WordPress dashboard. This brings our custom WP_List_Table much closer to the functionality of WordPress’ built-in administration screens.


What You’ll Learn

By the end of this lesson, you’ll know how to:

  • Read search keywords submitted by WP_List_Table
  • Pass search terms to your database query
  • Filter auction records using SQL
  • Keep pagination working while searching
  • Display only matching auctions

Why Search Matters

Imagine managing hundreds or even thousands of auctions.

Without search, finding Auction ID 357 or Listing ID 8421 would require scrolling through multiple pages.

A search box allows administrators to instantly locate records, improving productivity and making the plugin feel much more professional.


How WordPress Search Works

When you click the Search button, WordPress automatically sends the search keyword as a GET parameter named:

s

For example:

admin.php?page=flipnzee-all-auctions&s=44

Your plugin simply needs to:

  1. Read $_REQUEST['s']
  2. Pass it to the database
  3. Display matching records

Step 1 — Read the Search Term

Inside the table class, retrieve the search keyword submitted by WordPress.

Example:

$search = isset( $_REQUEST['s'] )
	? sanitize_text_field(
		wp_unslash( $_REQUEST['s'] )
	)
	: '';

Always sanitize user input before using it.


Step 2 — Pass the Search Term

Modify the call to retrieve auctions.

Instead of:

Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset
);

pass the search term as well:

Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset,
	$search
);

Step 3 — Update the SQL Query

Inside the Auction Manager, check whether a search keyword exists.

If it does, filter the results.

Example SQL:

WHERE
	id LIKE ?
	OR listing_id LIKE ?
	OR status LIKE ?

This allows administrators to search by:

  • Auction ID
  • Listing ID
  • Auction Status

Step 4 — Keep Pagination Working

Searching should not disable pagination.

Instead of counting every auction:

SELECT COUNT(*)

count only the matching records.

This keeps the page numbers accurate.


Step 5 — Test the Feature

Create several auctions.

Then try searches like:

44
draft
21

The table should immediately display only the matching auctions.


Security Considerations

Never place raw user input directly into SQL queries.

Always use:

  • sanitize_text_field()
  • wp_unslash()
  • $wpdb->prepare()
  • $wpdb->esc_like()

These functions protect your plugin against SQL injection attacks.


Common Mistakes

Many developers accidentally:

  • Forget to sanitize the search term
  • Build SQL using string concatenation
  • Break pagination after filtering
  • Ignore empty search values

Avoiding these mistakes results in a more secure and reliable plugin.


Expected Result

After completing this lesson:

  • ✅ Search box filters auctions
  • ✅ Pagination still works
  • ✅ Database queries remain secure
  • ✅ Administrators can quickly find auction records
  • ✅ The Auctions page behaves much more like WordPress core admin tables

Conclusion

Adding a search box was only the first step. Connecting it to the database transforms it into a practical tool for managing real auction data.

With searchable, paginated listings now in place, the Flipnzee Auctions plugin continues to evolve from a learning project into a production-ready WordPress plugin.


Lesson 27 Implementation — Adding Functional Search to the Flipnzee Auctions Table

In the Next Lesson

We’ll further enhance the Auctions table by allowing administrators to sort auctions by clicking the table headers, such as:

  • Auction ID
  • Listing ID
  • Start Price
  • Status
  • Created Date

This is another feature users expect from professional WordPress plugins and will make navigating large auction datasets even easier.

Lesson 27 Implementation — Adding Functional Search to the Flipnzee Auctions Table

Implementation Series: Building the Flipnzee Auctions Plugin Step by Step
Lesson: 27 (Implementation)
Prerequisites: Lessons 25 and 26 completed


Introduction

In Lesson 26, the Search Auctions box was added above the auctions table using WordPress’ built-in search_box() method. Although the interface looked complete, typing a keyword and clicking Search Auctions did not actually filter any records.

In this implementation lesson, the search box is connected to the database so administrators can quickly find auctions by Auction ID, Listing ID, or Status.

After completing this implementation, the search feature behaves much like the search functionality found on WordPress’ built-in Posts and Pages screens.


What Was Implemented

This lesson introduced the following improvements:

  • Added support for search keywords
  • Filtered database results using SQL
  • Used secure SQL queries with $wpdb->prepare()
  • Escaped wildcard characters using $wpdb->esc_like()
  • Updated pagination so it counts only matching results
  • Preserved the search keyword after searching

Step 1 — Update get_all_auctions()

Open:

includes/class-auction-manager.php

Locate the get_all_auctions() method.

Originally it accepted only pagination values:

public static function get_all_auctions(
	$per_page = 20,
	$offset = 0
)

Add a third parameter:

public static function get_all_auctions(
	$per_page = 20,
	$offset = 0,
	$search = ''
)

This parameter will receive the administrator’s search keyword.


Step 2 — Modify the SQL Query

Previously, every auction was returned regardless of the search box.

The method was updated to check whether a search keyword exists.

If a keyword is present:

  • Create a safe LIKE pattern using $wpdb->esc_like()
  • Filter records using WHERE
  • Return only matching auctions

Otherwise, return all auctions exactly as before.

This keeps the plugin efficient while remaining secure.


Step 3 — Read the Search Keyword

Open:

admin/class-auctions-table.php

Inside prepare_items(), retrieve the keyword submitted by WordPress.

The search box automatically sends its value using:

$_REQUEST['s']

The keyword was safely sanitized using:

  • wp_unslash()
  • sanitize_text_field()

This protects the plugin from unsafe input.


Step 4 — Pass the Search Value

Previously, auctions were loaded like this:

Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset
);

The search variable was added as the third parameter:

Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset,
	$search
);

Now the database query knows what the administrator searched for.


Step 5 — Update Pagination

Searching introduced one small problem.

Although only matching auctions appeared, pagination still counted every auction in the database.

To solve this:

The count_auctions() method was updated to accept the same search keyword.

Instead of counting every record:

SELECT COUNT(*)

the query now counts only matching auctions whenever a search is active.

This keeps pagination accurate.


Step 6 — Update the Table

The table’s total item count was changed from:

Flipnzee_Auction_Manager::count_auctions();

to:

Flipnzee_Auction_Manager::count_auctions(
	$search
);

This small change synchronizes the search results with the page numbers.


Step 7 — Test the Feature

Several searches were performed during implementation.

Examples included:

  • Auction ID
  • Listing ID
  • Auction Status

The table correctly displayed only the matching auctions.

Pagination also updated automatically.

For example:

Searching for:

24

displayed:

  • 1 matching auction
  • 1 item
  • No additional pages

This confirmed that both searching and pagination were working together correctly.


Security Improvements

Several WordPress security functions were used throughout this lesson.

These included:

  • sanitize_text_field()
  • wp_unslash()
  • $wpdb->prepare()
  • $wpdb->esc_like()

Using these functions helps protect the plugin against SQL injection and unsafe user input.


Troubleshooting

During implementation, one issue appeared.

The search results filtered correctly, but pagination still showed the total number of auctions.

The cause was simple.

The table was still calling:

count_auctions();

instead of:

count_auctions( $search );

After updating this single line, pagination immediately displayed the correct number of matching results.


Result

At the end of this lesson, the Flipnzee Auctions plugin now supports:

  • ✅ Professional search box
  • ✅ Secure database searching
  • ✅ Pagination integrated with search
  • ✅ Accurate item counts
  • ✅ WordPress coding standards

The Auctions screen now behaves much more like WordPress’ own administration pages.


Conclusion

This implementation transformed the search box from a simple interface element into a fully functional administrative tool.

Combined with pagination from the previous lesson, administrators can now quickly locate auctions even when the database grows significantly.

The Flipnzee Auctions plugin continues to evolve from a learning project into a production-ready WordPress plugin.


Download Files

The source code for this lesson is available below:

  • Starting Project: Download the plugin before implementing Lesson 27.
  • Completed Project: Download the updated plugin after implementing the functional search feature and compare your changes if needed.

In the next implementation lesson, we’ll add sortable columns, allowing administrators to click table headers such as ID, Listing ID, Status, and Created Date to sort auction records just like the native WordPress admin screens.

Lesson 26 Implementation — Adding a Search Box to the Auctions Table (Step-by-Step)

Plugin: Flipnzee Auctions
Implementation Stage: Lesson 26
Difficulty: Intermediate
Prerequisites: Lessons 1–25 completed


Introduction

In Lesson 26, we improved the usability of the All Auctions page by adding a search box to the auctions table. WordPress’ WP_List_Table class includes a built-in search box method, allowing administrators to quickly search records without creating a custom user interface.

During implementation, we also encountered and resolved a PHP syntax error that prevented the plugin from activating. This demonstrates why validating PHP files after every change is an important part of plugin development.


Objective

By the end of this implementation, the plugin will:

  • Display a professional search box above the auctions table.
  • Continue supporting pagination.
  • Prepare the plugin for full search functionality in the next implementation step.

Step 1 — Open the Admin Page File

Open:

admin/class-admin.php

Locate the following method:

public function all_auctions_page() {

This method is responsible for displaying the All Auctions page inside the WordPress admin area.


Step 2 — Wrap the Table Inside a Form

Replace the existing table output with a GET form:

<form method="get">

	<input
		type="hidden"
		name="page"
		value="flipnzee-all-auctions"
	>

	<?php

	$table->search_box(
		'Search Auctions',
		'flipnzee-search'
	);

	$table->display();

	?>

</form>

Using a GET form allows WordPress to send the search term as part of the page URL.


Step 3 — Display Success Messages

Before displaying the table, retrieve the message parameter:

$message = isset( $_GET['message'] )
	? sanitize_text_field(
		wp_unslash( $_GET['message'] )
	)
	: '';

Display the success notice:

<?php if ( 'deleted' === $message ) : ?>

<div class="notice notice-success is-dismissible">
	<p>Auction deleted successfully.</p>
</div>

<?php endif; ?>

This keeps the interface consistent with earlier lessons where auctions could be added, edited, or deleted.


Step 4 — Keep the Search Box Inside the Method

One mistake encountered during implementation was accidentally placing:

$message = ...

outside the all_auctions_page() method.

Doing so resulted in the following PHP parse error:

PHP Parse error:
syntax error,
unexpected variable "$message",
expecting "function" or "const"

The fix was simply moving the code back inside the method.


Step 5 — Validate the PHP File

Before uploading the updated plugin, validate the modified file.

From the project root:

php -l admin/class-admin.php

or from inside the admin folder:

php -l class-admin.php

Expected output:

No syntax errors detected in class-admin.php

Step 6 — Test the Plugin

After uploading the updated plugin:

  1. Activate the plugin.
  2. Navigate to:

Flipnzee Auctions → All Auctions

You should now see:

  • A search box above the auctions table.
  • Pagination continuing to work.
  • Existing auctions displaying normally.

At this stage, the search box is visible but not yet filtering results. That functionality will be added in the next implementation.


Troubleshooting

During this implementation, the following issue occurred:

Problem

The plugin could not be activated because of a PHP syntax error.

Cause

The $message variable and notice code had been placed outside the all_auctions_page() method.

Solution

Move the code back inside the method and validate the file using:

php -l

before uploading the plugin again.


Result

At the end of this implementation:

  • ✅ Search box added
  • ✅ Pagination still functional
  • ✅ Plugin activates correctly
  • ✅ Admin interface looks more professional
  • ✅ Foundation prepared for database search in the next implementation

Source Code

At the beginning of this article, you can download the plugin source code before implementing Lesson 26.

At the end of this article, you can download the updated source code after completing Lesson 26 and compare the changes with your own implementation.


Next: In the next implementation article, we’ll connect the search box to the database query so administrators can search auctions by ID, Listing ID, or Status while keeping pagination fully functional.

Lesson 25 Implementation Guide — Adding Pagination to the Auctions Table


Prerequisites

Before starting this implementation:

  • Lesson 25 has been completed.
  • The Auctions table is already displaying data using WP_List_Table.
  • Auctions can already be created, edited and deleted.

In this guide, we’ll implement pagination so the table can efficiently display a large number of auction records.


Step 1 — Modify get_all_auctions()

Open:

includes/class-auction-manager.php

Locate the existing method:

public static function get_all_auctions()

Replace it with a version that accepts two parameters:

  • $per_page
  • $offset

The SQL query should use:

LIMIT

and

OFFSET

so only the required records are retrieved from the database.

Why?

Without pagination, WordPress loads every auction record into memory.

With pagination enabled, only the current page of results is loaded.

This becomes much faster as the number of auctions grows.


Step 2 — Add a Method to Count Auctions

Still inside:

includes/class-auction-manager.php

Create a new method:

count_auctions()

This method simply returns:

SELECT COUNT(*)

from the auctions table.

Why?

The table needs to know:

  • total number of auctions
  • number of pages

before WordPress can generate pagination links.


Step 3 — Update prepare_items()

Open:

admin/class-auctions-table.php

Locate:

prepare_items()

Instead of loading every auction:

Flipnzee_Auction_Manager::get_all_auctions();

calculate:

  • current page
  • records per page
  • SQL offset

Then call:

Flipnzee_Auction_Manager::get_all_auctions(
    $per_page,
    $offset
);

Also configure:

set_pagination_args()

using the total auction count.


Step 4 — Upload the Updated Plugin

Compress the updated plugin.

Install it on the test website.

Visit:

Flipnzee Auctions
→ All Auctions

If enough auction records exist, pagination links should now appear beneath the table.


Step 5 — Test Pagination

Create multiple auction records.

Verify that:

  • Page 1 loads correctly.
  • Page 2 displays the next set of auctions.
  • Previous and Next links work.
  • Auctions remain sorted correctly.
  • Edit and Delete continue to work on every page.

Result

After completing this implementation, the Auctions table behaves much more like a professional WordPress administration screen.

Instead of loading every record at once, the plugin displays a manageable number of auctions per page, improving performance and scalability as the number of auctions increases.


What We Learned

In this implementation, we learned how to:

  • Modify database queries using LIMIT and OFFSET.
  • Count database records efficiently.
  • Configure pagination using WP_List_Table.
  • Calculate SQL offsets based on the current page.
  • Display paginated auction records in the WordPress admin area.

Download Source Code


Next Implementation Guide: Lesson 26 — Adding Auction Search Functionality to the Admin Table

Lesson 26 — Adding Search Functionality to the Auctions Table Using WP_List_Table

As the number of auctions grows, scrolling through multiple pages becomes inefficient. WordPress solves this problem by providing a built-in search box in WP_List_Table. In this lesson, we’ll integrate that search feature into the Flipnzee Auctions plugin so administrators can quickly locate auctions by ID, Listing ID, or Status.

By the end of this lesson, the Auctions screen will feel much closer to native WordPress admin pages such as Posts, Pages, and Users.


What You’ll Build

After completing this lesson, administrators will be able to:

  • Search auctions from the admin table.
  • Search by Auction ID.
  • Search by Listing ID.
  • Search by Status.
  • Combine search with pagination.
  • Display only matching auction records.

Why Add Search?

Imagine managing hundreds or even thousands of auctions.

Without search, finding Auction #437 would require browsing through many pages.

A search box allows administrators to locate records instantly, improving productivity and making the plugin feel much more professional.


How WordPress Search Works

WP_List_Table already provides a search box.

However, it only displays the search field.

It is the developer’s responsibility to:

  • Display the search box.
  • Read the search keyword.
  • Modify the database query.
  • Return only matching results.

Step 1 — Add a Search Box Above the Table

Update the All Auctions admin page.

Before displaying the table, output the search form using the built-in method:

$table->search_box(
    'Search Auctions',
    'flipnzee-search'
);

This automatically creates a familiar WordPress search field.


Step 2 — Read the Search Keyword

Retrieve the search term safely using:

  • sanitize_text_field()
  • wp_unslash()

If no search keyword is provided, continue displaying all auctions.


Step 3 — Update the Auction Manager

Modify the query that retrieves auctions.

If a search term exists, search multiple columns such as:

  • Auction ID
  • Listing ID
  • Status

using SQL conditions.


Step 4 — Count Matching Results

Pagination should work with search.

Instead of counting every auction, count only the matching auctions.

This ensures the page numbers remain accurate.


Step 5 — Preserve Search During Pagination

When moving from Page 1 to Page 2, the search keyword should remain in the URL.

Otherwise, WordPress would forget the search and display every auction again.


Step 6 — Test the Feature

Create several auctions with different:

  • Listing IDs
  • Prices
  • Status values

Then verify:

  • Searching by Listing ID returns the correct auction.
  • Searching by Status works.
  • Pagination still functions correctly.
  • No PHP warnings appear.

Example Workflow

Suppose your table contains:

Auction IDListing IDStatus
1101Draft
2215Active
3330Closed
4450Active

Searching for:

215

returns only Auction #2.

Searching for:

Active

returns Auctions #2 and #4.


Tips

  • Always sanitize search input before using it.
  • Use $wpdb->prepare() when building SQL queries.
  • Ensure pagination and search work together.
  • Test searches that return zero results.
  • Keep the search lightweight for better performance.

What We Learned

In this lesson, you learned how to:

  • Add a search box to a WP_List_Table.
  • Capture user search input securely.
  • Search auction records using SQL.
  • Combine search with pagination.
  • Build a more professional WordPress administration interface.

Next Lesson

In Lesson 27, we’ll make the Auctions table even more user-friendly by adding sortable columns, allowing administrators to sort auctions by:

  • Auction ID
  • Listing ID
  • Start Price
  • Reserve Price
  • Buy Now Price
  • Status
  • Creation Date

This will make managing large numbers of auctions much faster and more intuitive.