Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityDave Plummer Has Made the Task Manager of Your Dreams(21.09.2026 um 21:20 Uhr)
Sichere ProgrammierungSubqueries and CTEs: Asking a Question Inside a Question(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungTVL Trend Analysis & Liquidity Risk Assessment: Lido(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungReact is Officially Dead in 2026 (Thanks to AI)(21.09.2026 um 21:01 Uhr)
Sichere ProgrammierungUsing SHA256 to Build Trustworthy Data Portals in Brazil(21.09.2026 um 21:01 Uhr)
Sichere Programmierung🚀 I reached 1,001 views on DEV!(21.09.2026 um 21:03 Uhr)
Sichere ProgrammierungReact Mental Models 2(21.09.2026 um 21:05 Uhr)
Sichere ProgrammierungAustralian RAM and SSD prices climb as stock tightens(21.09.2026 um 21:09 Uhr)
Windows Tipps & SecurityDave Plummer Has Made the Task Manager of Your Dreams(21.09.2026 um 21:20 Uhr)
Sichere ProgrammierungSubqueries and CTEs: Asking a Question Inside a Question(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungTVL Trend Analysis & Liquidity Risk Assessment: Lido(21.09.2026 um 21:00 Uhr)
Sichere ProgrammierungReact is Officially Dead in 2026 (Thanks to AI)(21.09.2026 um 21:01 Uhr)
Sichere ProgrammierungUsing SHA256 to Build Trustworthy Data Portals in Brazil(21.09.2026 um 21:01 Uhr)
Sichere Programmierung🚀 I reached 1,001 views on DEV!(21.09.2026 um 21:03 Uhr)
Sichere ProgrammierungReact Mental Models 2(21.09.2026 um 21:05 Uhr)
Sichere ProgrammierungAustralian RAM and SSD prices climb as stock tightens(21.09.2026 um 21:09 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Dynamic AJAX Post Filtering by Taxonomy without any plugin in wordpress Using Radio Buttons.

Learn how to implement dynamic AJAX-based post filtering in WordPress. Fetch and display posts by taxonomy using radio buttons and checkboxes for seamless user interaction and improved functionality. First, we cover the functionality of…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Learn how to implement dynamic AJAX-based post filtering in WordPress. Fetch and display posts by taxonomy using radio buttons and checkboxes for seamless user interaction and improved functionality.

First, we cover the functionality of the radio button filter.

Step-1:

create js file and add this code:




jQuery(document).ready(function ($) {
// Fetch all worksheets by default when the page loads
fetchWorksheets();

// Trigger AJAX request when a grade filter is selected
$('.grade-filter').on('change', function () {
var taxonomy = $(this).data('taxonomy'); // e.g., 'worksheet-grad'
var term = $(this).val(); // Selected term slug
fetchWorksheets(taxonomy, term);
});

// Function to fetch worksheets
function fetchWorksheets(taxonomy = '', term = '') {
$.ajax({
url: ajax_object.ajax_url,
type: 'POST',
data: {
action: 'fetch_worksheets',
nonce: ajax_object.nonce,
taxonomy: taxonomy,
term: term,
},
beforeSend: function () {
$('.worksheet-container').html('<p>Loading...</p>');
},
success: function (response) {
if (response.success) {
$('.worksheet-container').html(response.data.html);
} else {
$('.worksheet-container').html('<p>' + response.data.message + '</p>');
}
},
error: function () {
$('.worksheet-container').html('<p>An error occurred. Please try again.</p>');
},
});
}




});







Step-2:

add this code in functions.php file:





// Register AJAX action for logged-in users (you can add for non-logged-in users too)
add_action('wp_ajax_fetch_worksheets', 'fetch_worksheets');
add_action('wp_ajax_nopriv_fetch_worksheets', 'fetch_worksheets');

function fetch_worksheets() {
// Verify nonce for security
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'ajax_nonce')) {
wp_send_json_error(array('message' => 'Nonce verification failed.'));
wp_die();
}

// Get taxonomy and term from the AJAX request
$taxonomy = isset($_POST['taxonomy']) ? sanitize_text_field($_POST['taxonomy']) : '';
$term = isset($_POST['term']) ? sanitize_text_field($_POST['term']) : '';

// Default query arguments
$args = array(
'post_type' => 'worksheet',
'posts_per_page' => -1, // Fetch all posts
);

// If a specific term is selected, modify the query
if (!empty($taxonomy) && !empty($term)) {
$args['tax_query'] = array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term, // Fetch posts of the selected term
),
);
}

// Run WP_Query to fetch posts
$query = new WP_Query($args);

// Check if any posts were found
if ($query->have_posts()) {
$html = '';
while ($query->have_posts()) {
$query->the_post();
// Output the post HTML
$html .= '<div class="card">';
$html .= '<h3>' . get_the_title() . '</h3>';
$html .= '<div class="worksheet-excerpt">' . get_the_excerpt() . '</div>';
$html .= '</div>';
}
wp_send_json_success(array('html' => $html));
} else {
wp_send_json_error(array('message' => 'No worksheets found.'));
}

wp_die(); // Always terminate the request properly
}







Step-3:

add this code in functions.php for enque custom js file in wp.






function enqueue_custom_scripts() {
wp_enqueue_script('custom-ajax', get_template_directory_uri() . '/js/custom-ajax.js', array('jquery'), null, true);

// Localize script to pass ajax_url and nonce to JS
wp_localize_script('custom-ajax', 'ajax_object', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax_nonce'),
));
}
add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');






Step-4:

The html code structure add this on your template file.




 <div class="grade">
<h2 class="filter-heading">GRADE</h2>
<ul>
<li>
<input type="radio" id="1st" name="radio" class="grade-filter" data-taxonomy="worksheet-grad" value="1st-grade" />
<label for="1st" class="font">1st Grade</label>
</li>
<li>
<input type="radio" id="2nd" name="radio" class="grade-filter" data-taxonomy="worksheet-grad" value="2nd-grade" />
<label for="2nd" class="font">2nd Grade</label>
</li>
</ul>
</div>






Note: please the css class on radio button change according your css class and data-taxonomy="worksheet-grad" alsoe. second important point is the value="2nd-grade" is change to your category slug.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Dynamic AJAX Post Filtering by Taxonomy without any plugin in wordpress Using Radio Buttons.

Thematisch verwandte Begriffe: Dynamic, AJAX, Post, Filtering · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-77582 | Tinyauth is an authentication and authorization server. Prior to 5.1.0, …
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick