Lesson 32 — Implementing a Fully Functional Status Filter in the Auctions Table

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


Introduction

In the previous lesson, we added a Status dropdown above the Auctions table. The user interface was complete, but selecting a status did not yet change the displayed records.

In this lesson, we’ll connect the status filter to the database so that it becomes fully functional. Administrators will be able to display only Draft, Active, or Closed auctions while continuing to use searching, sorting, pagination, and bulk actions.

By the end of this lesson, the Status filter will work exactly as expected in a professional WordPress administration screen.


What You’ll Learn

After completing this lesson, you’ll know how to:

  • Extend existing manager methods with additional filter parameters.
  • Build dynamic SQL queries based on optional filters.
  • Combine multiple filters within a single query.
  • Keep pagination synchronized with filtered results.
  • Preserve compatibility with searching, sorting, and bulk actions.
  • Follow WordPress database best practices.

Why Finish the Status Filter?

The previous lesson introduced the user interface, but administrators still could not actually filter auction records.

A fully functional status filter allows administrators to quickly answer questions such as:

  • Which auctions are currently active?
  • Which auctions are still drafts?
  • Which auctions have already closed?

Instead of manually browsing dozens or hundreds of records, administrators can focus on only the auctions they need.


Files We’ll Modify

During this lesson, we’ll update:

admin/class-auctions-table.php
includes/class-auction-manager.php

Implementation Overview

We’ll complete the feature in several small steps.


Step 1

Update get_all_auctions() to accept a new parameter:

$status

Step 2

Modify the SQL query so it supports four situations:

  • No search + No status
  • Search only
  • Status only
  • Search + Status

Step 3

Use prepared statements to safely build the SQL query.


Step 4

Update count_auctions() so pagination reflects only the filtered records.


Step 5

Ensure searching and status filtering work together.

Example:

Search:

Listing ID = 25

Status:

Draft

Expected result:

Only matching Draft auctions with Listing ID 25 should appear.


Step 6

Ensure sorting continues working.

After filtering:

  • Click Start Price
  • Click Created At
  • Click Listing ID

The filtered records should still sort correctly.


Step 7

Verify pagination.

When a filter reduces the number of matching auctions:

  • Page count should update automatically.
  • Only matching records should be counted.
  • Navigation should remain accurate.

Step 8

Test every possible combination.

Examples include:

SearchStatusExpected Result
NoneAllEvery auction
NoneDraftDraft auctions only
NoneActiveActive auctions only
NoneClosedClosed auctions only
Listing IDAllMatching listing
Listing IDDraftMatching Draft listing
Listing IDActiveMatching Active listing

Security Considerations

Throughout this lesson we’ll continue using WordPress security best practices.

User input should always be sanitized before use.

The implementation should continue using:

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

No SQL values should be inserted directly into queries.


Expected Result

After completing this lesson, administrators will be able to:

  • View all auctions.
  • Filter only Draft auctions.
  • Filter only Active auctions.
  • Filter only Closed auctions.
  • Search within filtered results.
  • Sort filtered results.
  • Paginate filtered results.
  • Continue using bulk actions.

The auction management screen will now provide a much more efficient way to work with large datasets.


Conclusion

Completing the Status filter transforms it from a simple user interface element into a fully functional management tool.

Together with pagination, searching, sortable columns, and bulk actions, the Flipnzee Auctions plugin now offers an administration experience that closely resembles the native WordPress dashboard.

This lesson also demonstrates an important software engineering principle: user interface elements are only valuable when they are correctly connected to the underlying application logic.

Lesson 31 Implementation: Adding Status Filters to the Flipnzee Auctions Plugin


In the Next Lesson

We’ll refactor the All Auctions page by separating GET and POST forms.

Searching, filtering, sorting, and pagination will use GET requests, while bulk deletion will use a dedicated POST form protected by a WordPress nonce.

This refactoring will improve code organization, simplify future enhancements, and align the plugin more closely with WordPress core development practices.

Lesson 31 Implementation: Adding Status Filters to the Flipnzee Auctions Plugin

In the previous lessons, we enhanced the auction management table with searching, pagination, sortable columns, and bulk actions. As the number of auctions grows, administrators need an easier way to view only auctions in a particular state.

In this lesson, we’ll add a Status Filter that allows administrators to display only Draft, Active, or Closed auctions.


Step 1: Add a Status Filter Dropdown

The first step is to add a filter control above the auction table.

Open:

admin/class-admin.php

Locate the all_auctions_page() method and add a dropdown before the search box.

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

<select name="status">

	<option value="">All Statuses</option>

	<option
		value="draft"
		<?php selected( $status, 'draft' ); ?>
	>
		Draft
	</option>

	<option
		value="active"
		<?php selected( $status, 'active' ); ?>
	>
		Active
	</option>

	<option
		value="closed"
		<?php selected( $status, 'closed' ); ?>
	>
		Closed
	</option>

</select>

<?php

submit_button(
	'Filter',
	'secondary',
	'',
	false
);

This creates a familiar WordPress-style filter that remembers the selected option after the page reloads.


Step 2: Read the Selected Status

Next, the selected status needs to be available while preparing the table data.

Open:

admin/class-auctions-table.php

Inside the prepare_items() method, read the selected status.

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

The filter value is sanitized before being used anywhere else in the plugin.


Step 3: Pass the Filter to the Manager Class

The manager class is responsible for retrieving auction records from the database.

Update the method calls inside prepare_items().

$total_items = Flipnzee_Auction_Manager::count_auctions(
	$search,
	$status
);

Likewise, update the method that retrieves the auction list.

$this->items = Flipnzee_Auction_Manager::get_all_auctions(
	$per_page,
	$offset,
	$search,
	$status,
	$orderby,
	$order
);

This allows the selected filter to travel from the user interface to the database layer.


Step 4: Update the Manager Method Signatures

Open:

includes/class-auction-manager.php

Update the method definitions to accept the new $status parameter.

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

Similarly, update the counting method.

public static function count_auctions(
	$search = '',
	$status = ''
)

Step 5: Apply the Status Filter to Database Queries

Modify the SQL queries so that they include the selected status whenever a filter has been chosen.

For example, if the administrator selects Draft, only auctions whose status is draft should be returned.

If All Statuses is selected, the query should continue returning every auction.

This approach keeps the filtering logic entirely inside the manager class.


Step 6: Update the Pagination Count

Pagination should display the number of filtered results instead of the total number of auctions.

For example:

  • 8 Draft auctions
  • 5 Active auctions
  • 12 Closed auctions

Each filtered view should have its own correct page count.


Step 7: Test the Feature

After uploading the updated plugin:

  1. Open Flipnzee Auctions → All Auctions.
  2. Select Draft from the Status dropdown.
  3. Click Filter.
  4. Confirm that only Draft auctions appear.
  5. Repeat the process for Active and Closed.
  6. Finally, choose All Statuses to display every auction again.

Also verify that:

  • Searching continues to work.
  • Sorting still functions correctly.
  • Pagination remains accurate.
  • Bulk actions continue working as expected.

Final Result

The auction management screen now includes a convenient Status filter that allows administrators to quickly narrow the list of auctions.

Instead of manually searching through every record, administrators can instantly display:

  • Draft auctions
  • Active auctions
  • Closed auctions
  • All auctions

This greatly improves usability, especially as the number of auction records grows.


What We Learned

In this lesson, we learned how to:

  • Add a custom filter control to a WordPress admin page.
  • Read filter values from user input safely.
  • Pass filter values through different layers of the plugin.
  • Update manager methods to support filtering.
  • Modify database queries based on selected filters.
  • Keep pagination accurate when filters are applied.
  • Preserve compatibility with searching, sorting, and bulk actions.

The Flipnzee Auctions plugin now provides an even more professional administration experience by allowing auction records to be filtered by status with just a few clicks.

Download Source Code

Download the starting version of the plugin before the lesson:

⬇ Download Plugin (After Lesson 30) (12 downloads )

Download the completed version after this lesson:

⬇ Download Plugin (After Lesson 31) (1 download )