logo
down
shadow

Wordpress category filter doesn't filter on sub categories


Wordpress category filter doesn't filter on sub categories

By : Adam Poole
Date : November 15 2020, 06:54 AM
should help you out You have to do several different WP_Query's with the restraining arguments to get only those posts you want. You will have to do several loops if you want it to limit them to one sub category.
You might have to make templates for these category pages and put your customized loops in there, or better to avoid repeating code, you make a category.php template in which you check the global $query in order to determine which sub category was asked and set the correct $args before generating the loop.
code :
'cat' => get_query_var( 'cat' )


Share : facebook icon twitter icon
Counting rows by category-filter during fetching of categories from database

Counting rows by category-filter during fetching of categories from database


By : SCB
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have two tables in my database , What you need can be done in SQL:
code :
SELECT companies.name, SUM(IF(company_id IS NULL, 0, 1)) AS products
    FROM companies
    LEFT JOIN products ON (companies.id = products.company_id)
    GROUP BY companies.id;
How to iterate Wordpress categories to create filter checkboxes by categories on a sidebar

How to iterate Wordpress categories to create filter checkboxes by categories on a sidebar


By : Ahmed Casanova
Date : March 29 2020, 07:55 AM
should help you out In my sidebar.php, I want to create filter checkbox on the sidebar as depicted in the above image. So my filter checkboxes would like in this hierachical format: , Finally able to do this.
Here's my code structure.
code :
<h2>Sidebar</h2>

<?php 

//Retrieve top-level categories
$parent_args = array(
  'orderby' => 'name',
  'parent' => 0,
  'hide_empty' => 0
);

//Retrieve first-level categories
$firstchild_args = array(
    'orderby' => 'name',
    'parent' => 0, //needs dynamic code here
    'hide_empty' => 0
);


$parent_categories = get_categories($parent_args);


foreach($parent_categories as $parent_category){


//create main headings for other categories other than Uncategorized.
if($parent_category->name!="Uncategorized"){
    $category_label = "Filter By ";
    echo '<h3 style="font-size: 20px; color: rgb(255, 255, 255);text-shadow: 2px 3px 0px rgb(0, 0, 0);">'.$category_label.''.$parent_category->name.'</h3>';

    //fetch the parent category's id
    $firstchild_args['parent'] = $parent_category->term_id;
    $firstchild_categories = get_categories($firstchild_args);

    //fetch all the first level children categories
    foreach($firstchild_categories as $firstchild_category){
        $output = "";
        $output = $output."<label class=\"checkbox\">";
        $output = $output."    <input type=\"checkbox\"><span style='font-size: 17px; color: rgb(255, 255, 255);text-shadow: 2px 3px 0px rgb(0, 0, 0);'>".$firstchild_category->name;
        $output = $output."</label>";

        echo $output;
    }

}

}

?>
How to filter categories based on URL on category.php in WordPress

How to filter categories based on URL on category.php in WordPress


By : Jan Kratochvíl
Date : March 29 2020, 07:55 AM
To fix this issue Get the slug of a current page, as mentioned in the link below. Then query posts with that category slug.
https://wordpress.stackexchange.com/questions/42117/how-to-retrieve-the-slug-of-current-page
Filter gallery to show all items of a category and all sub categories

Filter gallery to show all items of a category and all sub categories


By : Near
Date : March 29 2020, 07:55 AM
Category filter with 3 categories

Category filter with 3 categories


By : user3488000
Date : March 29 2020, 07:55 AM
it helps some times I have a WordPress query and filter with checkboxes by category: , It seems repetive code, I would recommend something like this:
code :
// first, set categories
$categories = array('vertragsart', 'zeitmodell', 'third_code');

foreach ($categories as $cat) {
    // if category is checked
    if (isset($_POST[$cat]) {
            // if $cats_array is assigned already, add category array, else, create $cats_array
        if (isset($cats_array)) {
            array_push(
                $cats_array, array(
                        'taxonomy' => 'category',
                        'field' => 'id',
                        'terms' => $_POST[$cat]
                )
            );
        } else {
            $cats_array = array(
            array(
                        'taxonomy' => 'category',
                        'field' => 'id',
                        'terms' => $_POST[$cat]
                )
            );
        }
    }
}

if (isset($cats_array) && is_array($cats_array)) {
    $args['tax_query'][] = $cats_array;
}
$categories = array('vertragsart', 'zeitmodell', 'third_code');

foreach ($categories as $cat) {
    // if category is checked
    if (isset($_POST[$cat]) {
      if (isset($cats)) {
                    $cats .= ',' $cat;
                } else {
                    $cats = $cat;
                }
    }
}

if (isset($cats)) {
    $args['category_name'] = $cats;
}
Related Posts Related Posts :
  • Dynamic image for user's ID
  • How to only upload specific parts of HTML form with PHP?
  • Dynamic PHP string as MySQL table name
  • What is the error in my query?
  • PHP Upstart on Amazon EC2 Linux (Elasticbeanstalk)
  • how to print dynamic variable value in php
  • php mysql insert values and select
  • uploading image in codeigniter controller
  • Converting htaccess to nginx for counter
  • how can I show my signal transaction data as project name
  • php raspberry pi trying to change pi date
  • PHP and mysql, SELECT query return null
  • Unable to store Date values in php mysql table that are existing in excel file
  • Can we include 2 Mail() functions in 1 Page?
  • Problems with chinese characters
  • How to apply a function to every foreach result?
  • Use of CONCAT in FROM clause
  • Tag endpoint combined with user endpoint with Instagram API
  • create dynamic time in php and mysql
  • How to break zero index comma separated value into individual string in php
  • PHP Login session and echoing username
  • PHP : Difference b/w new self and new object()
  • Turkish character issue while inserting into MySQL database with PHP
  • Insert data from one DB into another on a different server - servers not linked
  • Sorting an array of strings using values alphabetically and considering the cases of values in PHP
  • Unable to solve .htaccess url rewriterule, gives 404 for all pages
  • Dual URL Rewrite In PHP
  • How to change value of cdata inside a .xml file and then again save it using php
  • Using filters from other classes within rules method in Yii 2?
  • json_decode syntax error from valid json
  • PHP get directory of included file on Virtualhost
  • RSA in php is confusing
  • Order in order without using events
  • How do I download a batch of pictures from URLs stored in a MySQL database
  • How to find pattern matching and save to array with preg_match
  • laravel4 data is not inserting in a single field
  • How can i merge Rows of An HTML table fetched from Mysql
  • How to get the duplicate values in array?
  • Add "."(dot) in a Numbers
  • Zend 2 multiple layouts for 1 module setup
  • PHP - Codeigniter : Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open for reading, File does n
  • PHP Form Troubles
  • How to use if condition in my wordpress shortcode
  • Amazon S3 Data retrieval in URL for all the images in bucket
  • Convert Bangla date to standard English date
  • In Jquery how to redirect to another page?
  • Building an ecommerce site using Laravel: How do I view/route products based on their ID?
  • My kg and lbs conversion is always off by significant amount
  • How to use loop in comment section
  • Jqgrid with Datepicker
  • How to prevent opening an authenticated php web page?
  • phpexcel - Making file to download rather than saving in the server
  • Send radio box value with $_POST
  • Volley: How to extract JSONObject from String Response? Is it possible?
  • Adding Image to the Excel in phpexcel in php
  • Pass an array to Redirect::action in laravel
  • display file name in while loop without url
  • Snow by date php
  • How to Replace a value in SQL only to a certain extent
  • How do I use HTML & PHP forms to insert data into a database?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org