2
votes
List archived posts by subcategory
In your Avada's child theme update your category.php, if its there or else
create new file with that name and add the code as below:
<?php
$current_cat = get_queried_object();
echo 'Heading: '.$...
2
votes
How to show related posts by category or custom post type?
First you must make a query with a custom taxonomy or anything you would like to show your posts
function related_posts_by_taxonomy( $post_id, $taxonomy, $args=array() ) {
$query = new ...
2
votes
Accepted
How to obtain the recent posts without their content in an efficient way?
How to obtain the recent posts without their content?
The same way you would any other post, just don't use the post content.
Not fetching the post content will not improve performance, and may ...
2
votes
Accepted
JSON REST API Wordpress only showing first 10 categories
This is normal behaviour, you've not accounted for pagination. The REST API returns 10 results per page by default, and can be configured to return up to but no more than 100 per page.
You may be ...
2
votes
Accepted
Category title output before opening title tag
You can fix that by setting the second parameter for single_cat_title() to false, which then returns the title instead of echoing it (before the <title> tag), like so:
$title = sprintf('%1$s ...
2
votes
Accepted
Automatically redirect a page to a category that share the same slug
Well you can just turn the code 180 degrees from the linked question and problem solved.
Just kidding.
I would start with getting the current page slug, using that slug search for a category that has ...
2
votes
Accepted
Categories are not listing their respective products
Normally, while creating a store, you'd go with the third choice, items and categories/subcategories. This means that users can either choose products directly from the main page or refine their ...
2
votes
Accepted
Edit the_category (); for a hierarchical display
You could assign the post only to the child category, and call the function like so:
the_category( ' ', 'multiple' );
This will output (notice the whitepsace between the anchor tags):
<a href=&...
1
vote
Accepted
Exclude some categories from listing on the current post
The problem here is you're not using the proper hook because the_category is actually for modifying the HTML of the category list, and the 1st parameter for the hook is actually a string and not an ...
1
vote
WordPress link to post links to category (loop)
Found the problem It was theme (Impreza) related (thank you @cjbj).
When the blog post category was created, it created a loop via the theme:
incorrect:
correct:
1
vote
How to get the last category name of a child category?
I've finally figured out the result I wanted with get_categories:
get_categories( array(
'orderby' => 'name', // get the name of category
'order' => 'DESC', // descending order
...
1
vote
Accepted
How to display sticky or latest published post on the current category page it belongs to?
This code is certainly not perfect but it actually does the job :
<?php
// Store the current category ID :
$current_object = get_queried_object_id();
// Get sticky post :
$args = array(
'...
1
vote
Accepted
How can I display the number of post associated to a category in Twig/Timber Wordpress?
You're assuming that get_terms() returns an object with a count property, but it doesn't.
From the docs:
Return
(WP_Term[]|int[]|string[]|string|WP_Error) Array of terms, a count thereof as a numeric ...
1
vote
How to show a custom taxonomy in the theme?
Try using get_the_terms() instead of get_the_category(). The latter is for the default "category" taxonomy only, not custom taxonomies you register yourself. See developer.wordpress.org/...
1
vote
Getting the category title / description returns first matching post?
For categories/taxonomies you can use get_queried_object to get the current category. From there you can easily get the name. So from your example:
if ( is_category() ) {
$cat = get_queried_object(...
1
vote
Accepted
Change of category structure will cause two kinds of URLs for one post
when visiting the old structure URL, it will NOT be redirected to
the new one
That's because:
The default category taxonomy is hierarchical and so does the permalink structure, hence its rewrite ...
1
vote
Accepted
How do I attach a page to a category similar to how we attach media to a post?
No, media is attached to posts/pages using the post_parent column. This works because media is actually a post of type attachment in the database.
Categories however are not posts, and the way you ...
1
vote
How to import nested categories from XML file?
The following code snippet did the trick:
<wp:term>
<wp:term_id><![CDATA[1]]></wp:term_id>
<wp:term_taxonomy><![CDATA[category]]></wp:term_taxonomy>
...
1
vote
Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
Solved with:
add_rewrite_rule('^foo/page/([0-9]+)/?$', 'index.php?category_name=category1&paged=$matches[1]', 'top');
add_rewrite_rule('^foo', 'index.php?category_name=category1', 'top');
The ...
1
vote
Accepted
Stores category posts in an array
As Howard E said, without knowing more about what and how you want to reorder it's difficult to give you useful advice. Here's a good breakdown of the options and, here are some places to start.
If ...
1
vote
Change the name Category - Not change category name
Use taxonomy_labels_category filter (documented here: https://developer.wordpress.org/reference/hooks/taxonomy_labels_taxonomy/) in order to change any of the labels that you need changed.
Here's what ...
1
vote
Exclude subcategories from the url
Yes you can! Just select the primary category of the post.
I am sorry that this screenshot is german, but it is pretty self-explaining. Here we have a main group "Party" with a subgroup &...
1
vote
Display products for a category, sorted by post_excerpt
Now, you can use filter posts_orderby.
add_filter('posts_orderby', function($orderby) {
return str_replace(
'wp_posts.post_modified',
...
1
vote
Get the first post term
To summarize all the previous answers here is the helper gist I use. Does all the necessary checks and accepts same arguments as the get_the_terms() function.
function getTheFirstTerm($post, $taxonomy)...
1
vote
Getting categories id for all products in cart
The answer from @sally works great, as long as your products are Simple products.
If your product uses a variation, then the above code no longer works as the $cart_item['data'] does not return the ...
1
vote
How to add featured image for category (without a plugin)?
<?php
add_action ( 'category_edit_form_fields', 'addTitleFieldToCat', 10, 2 );
function addTitleFieldToCat( $tag, $taxonomy ) {
$cat_title = get_term_meta( $tag->term_id, '_pagetitle', true ...
1
vote
How to add featured image for category (without a plugin)?
Not everything needs a plugin.
If you want to add a simple field to add IMG URL use add_term_meta(), the update_term_meta() and get_term_meta() WP functions.
function addTitleFieldToCat(){
$...
1
vote
How to fetch the highest category in the hierachry for a specific post?
Another idea (which heavily depends on what you are viewing [single or archive] and also your taxonomy-structure) is to look for the term parent.
Maybe this can help you aswell ...
You were asking ...
1
vote
How to get primary category name in Wordpress new version
I've just refactored Eqhes answer. A little cleaner code :)
if (!function_exists('get_primary_taxonomy_id')) {
function get_primary_taxonomy_id($post_id, $taxonomy) {
$prm_term = '';
...
1
vote
wp_list_categories depth and number
You should add 'child_of' => 0,
That way you will display only Main categories aka children of 0.
$custom_args = array(
'orderby' => 'name',
'order' => 'ASC',
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
categories × 4757posts × 571
custom-post-types × 496
php × 308
taxonomy × 299
custom-taxonomy × 284
wp-query × 274
loop × 271
tags × 230
permalinks × 212
customization × 198
woocommerce-offtopic × 190
archives × 188
functions × 170
plugins × 163
terms × 159
pages × 134
menus × 124
templates × 118
filters × 117
pagination × 101
query-posts × 100
theme-development × 98
custom-field × 93
query × 92