Tag Info

New answers tagged

1

You are wrongfully handling the WP_Query parameters. You can either use a query string type input or an array based one. Personally I much prefer the array type, so my example uses it: $category_id = (int) $child_category->term_id; $des_post_args = array( 'post_type' => 'tour', 'cat' => $category_id ); $des_post = new WP_Query( ...


0

Please add two new argument into your $args array. 1) Style with none value. See the markup section for more. 2) echo with 0(False). Now call and store the result into $categories variable and print it via printf(). Final code like: $args = array( 'taxonomy' => 'product_category', 'hide_empty' => 0, 'orderby' ...


0

You can specify the style argument as something other than the default (which is list) and it won't wrap the output in a <li>. You can then wrap it in a <div> yourself. Combine it with the echo argument if you need to check that the list isn't empty. Example: $args = array( 'taxonomy' => 'product_category', 'hide_empty' ...


0

in_category() is the incorrect function to use. This function checks that the current post object (which equates to the first post in the loop on an archive) is in the given category. The function you need is is_category() which checks that the current query is for the archive of the given category.


0

review https://codex.wordpress.org/Function_Reference/in_category vs https://codex.wordpress.org/Function_Reference/is_category to check for a category archive, use https://codex.wordpress.org/Function_Reference/is_category


0

I did this to solve the problem <?php $terms = get_the_terms( $post->cat_ID , 'product_cat' ); foreach ($terms as $term) { $term_id = $term->term_id; $term_link = get_term_link( $term, $taxonomy ); $term_name = $term->name; echo '<a class="cat-box" href="' . $term_link . '"><span ...


0

yes we can hide category by using plugin yoast seo got to advanced of seo and in that go to permalinks mark up the 1st option Strip the category base (usually /category/) from the category URL " and save its all done now


0

I usually do this by getting data from database $result = mysql_query("SELECT * FROM wp_terms JOIN wp_term_taxonomy ON wp_term_taxonomy.term_id = wp_terms.term_id WHERE wp_term_taxonomy.parent = ".$parent_cat_ID." AND wp_term_taxonomy.taxonomy = 'product_cat'");


0

I couldn't find any other way to resolve this problem. i tried a lot of thing to add link to the category menu but without any success.


0

an echo before inserting content, are you sure ? Possibly sending headers, blocks insert POST request and set pid to empty value. if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter some notes'; }


-2

use this code for solving your problem. <?php $args = array( 'orderby' =>'name', 'texonomy' =>'category', 'child_of' =>0, 'parent' =>0 ); $cats = get_categories($args); foreach ($cats as $cat) { echo $cat->name; $arg = array('orderby' => 'name', ...


0

EDIT: On a post page, the categories are already seen in hierarchical manner but with checkboxes. So, I have assumed that you have to show list of all the categories/subcategories somewhere in the admin panel in following format. Category 1 Sub-Category 1.1 Sub-Category 1.2 Category 2 So, presentation is upto you, I have just given logic to pull ...


1

use this code for access categories $args = new WP_Query( array( 'type' = 'post', 'taxonomy' = 'taxonomy_name', 'order' = 'ASC', 'orderby' = 'id' )); //this function are used for access all categories $query = get_categories($args);


1

As of PHP 5.4, you can directly dereference an array, so to get the first term, you can simply do. $first_term = get_the_terms( $post->ID, 'TAXONOMY_NAME' )[0]; var_dump( $first_term ); If you need a specific property (say the term name) of the first term, you can do the following $first_term_name = get_the_terms( $post->ID, 'TAXONOMY_NAME' ...


0

how about directly access the key of object? $terms = get_the_terms( $post->ID, 'sitecat' ); $first_term = $terms[0]; so you can access the object. echo $first_term->name;


2

the id of the categories is autoincrement so you can sort by id to find the last one : $args = array( "type" => "post", "orderby" => "id", "order" => "DESC", "number" => "5", "taxonomy" => "category", "hide_empty" => FALSE, // TRUE or FALSE depending what you want ); $categories = get_categories($args);


0

If you change the theme's home page to a static page, you would need to code the static page yourself to show recent posts or recent comments. Generally, the default home page is coded to have features like "recent blog posts" show by default. There are a few ways to achieve what you are looking for, but it will involve some hard coding and preferably the ...


0

To assign the blogs 'away' from the home page, create and publish a new page called 'Blog'. Leave it empty. In your WordPress Dashboard, go to Settings --> Writing. Front page displays: A static page (then select that page) + Posts Page: "Blog". Save your settings and it should work.


0

I have found a SOLUTION!!! (After endless research.. I can have CUSTOM POST TYPE permalinks like: example.com/category/sub_category/my-post-name here the code (in functions.php or plugin): //===STEP 1 (affect only these CUSTOM POST TYPES) $GLOBALS['my_post_typesss__MLSS'] = array('my_product1','....'); //===STEP 2 (create desired PERMALINKS) ...


0

As an alternative to editing the meta template, you can prevent the meta information from being displayed on single product pages at all. This can be handy if you also don't want to display the SKUs. Here is how to do it: remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 ); It goes to your functions.php.


2

In addition to Milo's answer: In wp::parse_request() the request URI is matched against the rewrite rules stored in $GLOBALS[ 'wp_rewrite' ]->rules. That means, the »route« will be parsed into query variables. The actual matching rule is stored in $GLOBALS[ 'wp_rewrite' ]->matches which is quite helpful for debugging: add_action( 'wp_footer', ...


2

parse_query is where the majority of the work is done. Query vars and is_ conditionals are set, and template-loader.php just checks those is_ conditional tags to load the appropriate template.


0

No Category is an taxonomy but not an custom taxonomy. Custom taxonomies need to be created via code, and you will have an different type of categories.


1

This will definitly remove word category . Add this code in functions.php.As you already know woocommerce_template_single_meta is the hook responsible for meta information of the single-product. File is present in /woocommerce/templates/single-product/meta.php. Either you can use the following code to edit the html of meta.php or you can copy the file ...


0

You can add categories and pages with a hook function add_taxonomies_to_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_taxonomies_to_pages' );


0

// remove the delete link for the specific category function category_row_actions( $actions, $tag ) { if ( $tag->term_id == PROTECTED_TERM_ID ) unset( $actions['delete'] ); return $actions; } // create the category if not excists (in case it's removed again in another theme) if (file_exists (ABSPATH.'/wp-admin/includes/taxonomy.php')) { ...


1

Your problem is that you've misunderstood how categories work. To demonstrate this, I'm going to use a hypothetical taxonomy called "colour": Alice creates a post called 'box', and gives it the category "pale red". The pale red category is a sub category of a top level category named "Red", such that Pale Red is a child of Red. Alice shows Bob the ...


1

You can make use of the get_the_categories filter to remove the parent categories from the list. the_category() uses get_the_category_list() which in turn uses get_the_category() The idea is to check the categories returned against an array of parent ids and then removing those categories from the list. You can try the following (Requires PHP 5.3+) ...


0

Use wp_set_object_terms( $object_id, $terms, $taxonomy, $append ); to get this done. You are adding everything with add_post_meta which will not add category to your post type. wp_set_object_terms( $post_id, sanitize_text_field($_POST['some_field'] ), 'schooltype', true ); But here I am also not sure how to assign parent-children relationship via ...


0

The simplest solution: echo get_the_category_list( ', ' ); Following your way: Change your $args like so: $args = array( 'template' => '%2$l', 'term_template' => '%2$s', ); And then, add this to your functions.php file (this will affect all %l markers!); add_filter( 'wp_sprintf_l', function($templates) { // ...


3

You can do this with pre_get_posts. This hook is called after the query variable object is created, but before the actual query is run. For excluding category id 32 and 39 from homepage, you can setup a function like this. function wpse_exclude_categories( $query ) { if ( is_admin() ) return; if ( $query->is_home() && ...


0

I have created a custom post type called "whiz_qt_quote". The custom post type uses categories. I have created a shortcode for all the post [quote]. What I would like to display one category post on one page. So instead of using the shortcode [quote], it would be something like [quote category="motivation"] and it would only display the posts from the ...


0

@GrSrv It is not possible in vanilla WordPress as the tags, and categories are separate entities. Categories would offer you a hierarchical parent/child relationship, and could accomplish this. CategoryParent1 CategoryChild1 CategoryGrandchild1, CategoryGrandchild2, CategoryGrandchild3 CategoryParent1 CategoryChild2 CategoryGrandchild1, ...


0

Absolutely. Since you can instantiate to a variable a query you can do it as much times as you want. Of course query loops require a lot of connections to the database so you have to be careful. Very often if you need many subqueries it basically means that your workflow can be enhanced in some way. Example of a subquery: $some_posts = new WP_Query(); ...


-1

this code will display the post from all taxonomy in wordpress: $args = array( 'type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'hierarchical' ...



Top 50 recent answers are included