New answers tagged

0

If I understand you correctly, you're basically wanting to grab one post from each taxonomy term. And then get that post's link. WP_Query is your friend here - with a custom query, you can get posts with almost any criteria you want (check the docs I've linked to there, they outline almost everything you can do). The criteria in this circumstance is a ...


1

I did this for a client and it looked like this: The PHP code: <dl class="tree-accordion"> <?php $currentyear = date("Y"); $years = range($currentyear, 1950); foreach($years as $year) { ?> <dt><a href=""><i class="fa fa-fw fa-plus-square-o" aria-hidden="true"></i> <?php echo $year; ?></a&...


0

With get_term_children you are retrieving a flat array of all child terms. What you want is an array with only the first child terms. Unfortunately there is no immediate way to retrieve this, so it has to be done in two steps: $parent_term = get_term_by('slug', 'bedroom', 'your_taxonomy_slug'); This gives you the 'bedroom' taxonomy term. Now you can use ...


4

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You could get the year from the published $post->post_date... So that when doing the query just use the date argument: $args = array( 'post_type' => $...


0

You can create a template page and use the WP loop: taxonomy-{taxonomy}-{term}.php https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/ Or you can use the get_posts functionality: https://codex.wordpress.org/Template_Tags/get_posts#Taxonomy_Parameters Something like this maybe: <?php $args = array( '...


0

t should be noted that if has_archive is set to true while registering the Custom Post Type, the post type archive /cptslug/ will be internally rewritten to ?post_type=cptslug. So this would also mean is_post_type_archive() will return true. Unfortunately, where the registered rewrite slug is different to the post type, you are not actually reliably ...


-1

If you have a lot of tags this is going to be pretty inefficient, but still, it should get the job done... This first part is a little pointless but it will pare down to posts in the category that actually have tags. add_action('pre_get_posts', 'get_category_tag_posts'); function get_category_tag_posts($q) { if ( !is_admin() && $q->...


3

There really is no sane way to accomplish this, specially if you have posts that are assigned to more than one tag (which is almost always the case). What is very sure, you have you work cut out for you. Here are some thought and ideas you can persue: POSTS WITH MULTIPLE TERMS If posts have more than one tag (or any term for that matter) assigned to them, ...


0

You can use this code: $queried_object = get_queried_object(); $posttype_slug = $queried_object->query_var; echo $posttype_slug; use $posttype_slug var whatever you need


0

You can use post_type_archive_title( $prefix = '', $display = true ): <h1><?php post_type_archive_title() ?></h1>


0

Even if default posts are stored in same table but they have different behavior and different characteristics. CPT has post type archive but default post type archived is called as blog and the taxonomy filter is called as tag/category archive. You can access the category/tag archive using For categories: /?cat={category_id} //e.g. ?/cat=5 For tags: /...


0

I created the following, fairly simple function in order to make the pages a higher importance than categories when loading the content. (Note: this may not the best, but a simple way. I found an issue, when using the Advanced Custom Fields plugin, it doesn't insert the custom fields neither of the old, nor of the new page by default. Adding ...


0

archive.php is very broad template, possibly used for many kinds of archives. If you mean common reverse chronological view the link to that would be return of get_post_type_archive_link() for the specific post type. Note that the native post post type is special case. For it archive is typically either site root or posts page, depending on site's ...


0

The URL for archive.php to list all posts which do not have a category assigned is: http://example.com/uncategorized/ This can be found be going to any post which has not been assigned a category, and examining the URL. Just remove the post slug to arrive at the relevant archive: http://local.example.com/uncategorized/hello-world/



Top 50 recent answers are included