Plugin Directory

Changeset 3252749


Ignore:
Timestamp:
03/09/2025 05:38:18 AM (13 months ago)
Author:
wpeasytools
Message:

Category filter solved.

Location:
content-shortcode-generator
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • content-shortcode-generator/trunk/content-shortcode-generator.php

    r3244521 r3252749  
    33 * Plugin Name: Content Shortcode Generator
    44 * Description: Create any type of content using Gutenberg editor and insert it anywhere via shortcodes.
    5  * Version: 1.0
     5 * Version: 1.1
    66 * Author: WPEasyTools
    77 * Author URI: https://wpeasytools.com/
     
    147147
    148148    $taxonomy = 'contshge_category';
     149    $selected = '';
    149150
    150 
    151     // Verify Nonce Security Check
    152     $nonce = isset($_GET['my_nonce']) ? sanitize_text_field(wp_unslash($_GET['my_nonce'])) : '';
    153 
    154     if ($nonce && wp_verify_nonce($nonce, 'my_action')) {
    155         $selected = isset($_GET[$taxonomy]) ? sanitize_text_field(wp_unslash($_GET[$taxonomy])) : '';
    156     } else {
    157         $selected = ''; // Default if nonce check fails
    158     }
    159 
     151    // Securely get the category filter value
     152    $selected = filter_input(INPUT_GET, $taxonomy, FILTER_SANITIZE_STRING);
    160153
    161154    $terms = get_terms(array(
     
    179172}
    180173add_action('restrict_manage_posts', __NAMESPACE__ . '\\contshge_filter_by_category');
     174
     175/**
     176 * Modify the Query to Filter Posts by Selected Category
     177 */
     178function contshge_filter_content_by_category_query($query) {
     179    if (is_admin() && $query->is_main_query()) {
     180        // Get and sanitize input safely
     181        $post_type = filter_input(INPUT_GET, 'post_type', FILTER_SANITIZE_STRING);
     182        $category_slug = filter_input(INPUT_GET, 'contshge_category', FILTER_SANITIZE_STRING);
     183
     184        if ($post_type === 'contshge_content' && !empty($category_slug)) {
     185            $query->set('tax_query', array(
     186                array(
     187                    'taxonomy' => 'contshge_category',
     188                    'field'    => 'slug',
     189                    'terms'    => $category_slug,
     190                ),
     191            ));
     192        }
     193    }
     194}
     195add_action('pre_get_posts', __NAMESPACE__ . '\\contshge_filter_content_by_category_query');
  • content-shortcode-generator/trunk/readme.txt

    r3244521 r3252749  
    11=== Content Shortcode Generator ===
    2 Contributors: sachinrp23
     2Contributors: wpeasytools
    33Donate link: https://www.wpressblog.com/
    44Tags: shortcode, Gutenberg, content, custom post type, Gutenberg block
    55Requires at least: 5.0
    66Tested up to: 6.7
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88Requires PHP: 7.2
    99License: GPLv2 or later
     
    5353== Changelog ==
    5454
     55= 1.1 =
     56* Category filter solved.
     57
    5558= 1.0 =
    5659* Initial release with custom post type, category taxonomy, shortcode generation, Gutenberg block support, and admin integration.
    57 
    58 == Upgrade Notice ==
    59 
    60 = 1.0 =
    61 No changes required. Just enable and start creating content with shortcodes.
    6260
    6361== License ==
Note: See TracChangeset for help on using the changeset viewer.