A section of php code that shows all categories. I want to change it to show specific categories. thank you!

Source: Internet
Author: User
A section of php code that shows all categories. if you want to change it to display a specific category, you can find add_filter ('Get _ terms ', 'get _ subcategory_terms', 10, 3 );
Function get_subcategory_terms ($ terms, $ taxonomies, $ args ){
$ New_terms = array ();
If (in_array ('product _ cat', $ taxonomies )&&! Is_admin () & is_shop ()){
Foreach ($ terms as $ key => $ term ){

$ New_terms [] = $ term;

}
$ Terms = $ new_terms;
}
Return $ terms;
}
This section is the current code. in my database, there is a table with a field term_id. I have saved the term_id of the category to be displayed in $ duqu. I want to ask how to insert this variable to it. only the selected term_id categories can be displayed in the code. thank you.


Reply to discussion (solution)

The code you provided cannot find term_id and $ duqu.

If you want to meet your requirements, just pass a judgment!

The code you provided cannot find term_id and $ duqu.

If you want to meet your requirements, just pass a judgment!

Sorry, I just came back to read my post.
The code is included in the program. I don't know much about the term_id and so what I export from the database table. so the variable names may be different.
I found a solution after studying it, but there is something difficult to solve. Please check if you will thank me.

If (! In_array ($ term-> slug, array ())){
$ New_terms [] = $ term;
}

I used this program to make some categories not displayed. for example, if I don't want to display A slug value as A classification, I can write it as array ('A ').
But I don't think there are many
$ Shaixuankuwp_terms = mysql_query ("SELECT * FROM 'WP _ terms 'where term_id ='". $ duqu_term_id ."'");
This section filters out all rows in the table that I want not to display.
While ($ duqushujukuwp_terms = mysql_fetch_array ($ shaixuankuwp_terms) {$ duqu_slug = $ duqushujukuwp_terms [slug];}
I read the slug of the classification in one row.
But I don't know how to put $ duqu_slug in the above array (). It seems that the array () cannot be put in one row.
Code placement to help you see how to change it. thank you.

While ($ duqushujukuwp_terms = mysql_fetch_array ($ shaixuankuwp_terms) {$ duqu_slug [] = $ duqushujukuwp_terms [slug];}

$ Duqu_slug is the array of rows you do not want to display.

While ($ duqushujukuwp_terms = mysql_fetch_array ($ shaixuankuwp_terms) {$ duqu_slug [] = $ duqushujukuwp_terms [slug];}

$ Duqu_slug is the array of rows you do not want to display.
Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.