New answers tagged

1

You can use get_ancestors: <?php if ( $terms = get_ancestors( get_queried_object_id(), 'category', 'taxonomy' ) ) { $crumbs = []; foreach ( $terms as $term ) $crumbs[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term ) ), esc_html( $term->name ) ); echo implode( ' > ', array_reverse( $crumbs ) ); } ...


-1

Ok managed to get the children and parents to loop out correctly. $catid = get_query_var( 'cat' ); while( $catid ) { $cat = get_category( $catid ); // Get the object for the catid. $catid = $cat->category_parent; // assign parent ID (if exists) to $catid // the while loop will continue whilst there is a $catid // when there is no longer ...


0

This query will help you global $wpdb; $cat_id = 65; // this query will get parent relationships from term_taxonomy table and get category names from terms table $category = $wpdb->get_row( "SELECT t4.term_id as parent_id, t4.name as parent_name, t5.term_id as grandparent_id, t5.name as grandparent_name FROM `{$wpdb->prefix}term_taxonomy` t1 ...


0

I believe there is no such "All Categories" archive page natively (because it would be just like the blog page - since every post have a category) . I recommend you to create a page template copying that code and modifying the query to include all posts and then creating a page with the slug 'category'. <?php /* * Template Name: Category */ ?> ...


0

Yo don't need to write a plugin for that - what you need already exists. Check this link: https://wordpress.org/plugins/list-categories/ With this plugin you can display categories in any post or page. Of course, maybe you want to write your own plugin, and in that case this link can be helpful. I hope that this will help you to speed up a process.


0

I've modified your code to reflect the wp_list_categories() function reference as suggested by @Usce. This snippet will create an unordered list, remove the "Categories" list title, and add the li class with individual category ID so you can target each link in the list. function catting ($atts, $content = null) { echo '<div id="cats" ...


-1

There is build in wordpress function for that , so you can use wp_list_categories() for that. Please refer here to learn more And after you display them you an do some CSS if you want to display it as buttons. I hope this helps. Kind regards, Usce


0

This is a custom template file not a taxonomy file, so get_query_var will not work for categories here, put get_category link inside the foreach loop as keesiemeijer said, and pass category id inside the function. Try this code, it will surely work. (Y) <?php /* Template Name: Categories */ get_header(); $cats = ...


0

Hopefully this is what you were asking for? Make sure you update your permalinks (just click update) afterwards. This will do yourwebsite.com/vege/%vege-category%/%post% In your example, you didn't register the taxonomy type, and additionally you need to add the function to put the category slug into the permalink. function my_custom_post_vege() { ...


0

To add to what @brasofilo answered 3 years ago, this is what is necessary in the current menu system (WP v4.5.1). add_action( 'admin_head-edit-tags.php', 'modify_menu_highlight_wpse_43839' ); function modify_menu_highlight_wpse_43839() { if( 'post_tag' == $_GET['taxonomy'] ) { ?> <script type="text/javascript"> ...


0

Your question it make sense to me my friend but the get_categories don't have the option to order by "meta_value_num" and then order by custom fields. What you can do is order after you get the array using the usort php function: $all_subcategories = array('parent' => $categoryID); $categories = get_categories( $all_subcategories ); ...


1

I use the following for multiple post types, just replace foo and bar with your own post types: $args = array( 'post_type' => array( 'foo', 'bar' ), 'orderby' => 'post_date', // other parameters as needed ); $q = new WP_Query( $args ); if ($q->have_posts()) : while ...


0

You could do this with a simple script. IMPORTANT! - Backup your database before doing this & attempt at your own risk. Create a file called changeauthorcat.php in your main WordPress folder. <?php include( 'wp-config.php' ); global $wpdb; // Author username $username = 'exampleuser'; // New category slug $newCatSlug = 'examplecategory'; // find ...


0

You can get author posts id's ids =[] ids = SELECT id FROM `wp_posts` WHERE `post_author`=1 and then you can loop result new_category_id = 999 old_category_id = 111 for id in ids: UPDATE `wp_term_relationships` SET `term_taxonomy_id`=new_id WHERE `object_id`=id AND `term_taxonomy_id`=old_category_id or wp_set_post_categories( $post_ID, ...


9

Update 1: Thanks to @birgire for suggesting a better way: wp_list_categories( [ 'include' => wp_list_pluck( get_the_category(), 'term_id' ) ] ); Try this in your single.php template: $current_cats = get_the_category(); $current_cats_ids = []; foreach ($current_cats as $cat) { $current_cats_ids[] = $cat->term_id; } wp_list_categories([ ...


0

You can use the cat_is_ancestor_of() function to check for child categories. http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of


0

If anyone's interested, the solution was quite close, I only had to specify the rewrite rule with &post_type=film : add_rewrite_rule( 'projections_dvd/([^/]+)/?$', 'index.php?name=$matches[1]&post_type=film&is_projections_dvd=1', 'top' ); I also changed the query vars to make it simpler : function wpd_query_var( $query_vars ) { ...


0

I had to code an external program, I can't see any other way. I used Java JDBC in my case. Query: SELECT p.post_title, m.meta_value FROM wp_term_taxonomy tt INNER JOIN wp_term_relationships tr on tt.term_taxonomy_id = tr.term_taxonomy_id inner join wp_posts p on p.ID = tr.object_id inner join wp_posts p2 on p.ID = p2.post_parent inner join wp_postmeta m on ...


2

Probably the most "WordPress-y" approach to such a problem is to store the date of your 'event' custom post-type in the post's metadata. Enabling users to set meta-data on a post is usually accomplished by using the 'register_meta_box_cb' argument to the register_post_type() function to add an extra "meta box" interface to the pages for creating or editing a ...


1

Inside get_posts() of WP_Query class, you will see this code block. /* * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and * 'category_name' vars are set for backward compatibility. */ if ( ! empty( $this->tax_query->queried_terms ) ) { /* * Set 'taxonomy', 'term', and 'term_id' to the * first taxonomy other than 'post_tag' or ...


0

There's actually a built-in Wordpress function for that: wpautop. It's more flexible than nl2br. Use the Wordpress function like so: wpautop(category_description( $category_id ) ); It will change the new and empty lines into paragraph tags automatically.


2

Try this: $post = get_post(); // If $post is already available, skip. $terms = get_the_terms( $post->ID, 'category' ); foreach ( $terms as $term ) : if ( $term->parent === 0 ) : echo '<a href="' . esc_url( get_term_link( $term->term_id, 'category' ) ) . '" title="' . esc_html( $term->name ) . '" ' . '>' . esc_html( ...


0

I am unable to comment. so i am answering here.. please check the link. May this help you. Click Here for the answer


-3

I used the content views plugin to make the list ( https://www.contentviewspro.com/ ) and then just put in short codes for each category list, separated by headings. You can see the result here: http://leakagemanagement.dk/white-papers-and-reports/ All the best Michael


0

add_action('pre_get_posts','search_filter_exc_posts'); function search_filter_exc_posts($query) { // Verify that we are on the search page & this came from the search form if($query->query_vars['s'] != '' && is_search()) { $q_tax_query = $query->query_vars["tax_query"]; // append product categories to current tax ...


3

You may need to include a tax_query for the Woocommerce taxonomy (called 'product_cat'): $tax_query = array( array( 'taxonomy' => 'product_cat' ), ); $query->set( 'tax_query', $tax_query ); } return $query; } However, you'll have to ensure that you can return posts AND pages AND product categories and also ...


0

404 Possible Error Cases with Permalinks check your apache config and make sure the directory is right. restart the apache process along with MYSQL/similar. make sure mod_rewrite is enabled Apache mod_rewrite for Ubuntu/Debian: sudo a2enmod rewrite sudo service apache2 restart Similliar to mod_rewrite for Nginx by .htaccess: a simpler way is ...


0

I may be jumping to a conclusion without seeing your code first. But I believe this may simply be because the way have your permalinks setup. If you go to your dashboard then settings->permalinks and change the option to anything other than Plain.


0

Try this: $the_cat = 'latest'; $term_args = array('orderby' => 'term_id', 'order' => 'ASC', 'fields' => array('term_id', 'slug')); $terms = wp_get_post_terms( $post->ID, 'category', $term_args ); foreach($terms as $term){ if($term->slug !== $the_cat){ $terms_to_exclude .= $term->term_id.','; } } $next_post = ...


1

First set a function to be used later with a usort to sort the categories by date of most recent post: function orderByDate( $a, $b ) { return strtotime($a['date']) - strtotime($b['date']); } Get your categories as you were doing: $args = array( 'hide_empty'=> 1 ); $categories = get_categories($args); ...


0

After banging my head for hours, I found this plugin very helpful. https://wordpress.org/plugins/custom-post-type-permalinks/ Below is the screen shot of options it gives.


0

you would need to use the date query: $args = array ( 'cat' => '1234', // if category being used 'post_type' => 'events', // if custom post type 'paged' => get_query_var('paged'), 'order' => 'DESC', 'paged' => $paged, 'date_query' => array( // this is the thing you need array( 'before' => array( // this ...



Top 50 recent answers are included