I used Pods to create both a custom post type and a custom taxonomy (in a custom theme), let’s call the CPT “picture” and the taxonomy “motive” for the following example. I assigned the “motive” taxonomy exclusively to the “picture” CPT.
The CPT works well – I created a php template (single-picture.php) for its single pages, in which I used the WP function the_taxonomies()
. This displays the name/s of the current taxonomy term/s of the post, linked to their archive pages (actually I only have one term per post, so it’s only one link). BTW: I am not even sure if “term” is the right word here – what I mean is something like the category name, but applied to taxonomies.
Now let’s say the taxonomy term is “landscape”. So that link calls an URL like https://www.example.com/motive/landscape
when clicked. Since the “motive” taxonomy is only used for the “picture” CPT, I would expect all “picture” custom posts which have the “landscape” term assigned to them to be displayed in a list, like regular posts on a blog page. However, the resulting page (which uses the “index.php” template) displays no posts, but instead the message which is written in the else
part of the WP loop!
Now, I *can* create a taxonomy-motive.php
template and use a custom query in it, querying the desired CPT and taxonomy name, which works. But I would expect that also the standard WP loop/query in the index.php file returns a list of those posts?
Did I oversee anything or will a regular WP loop really *not* display any posts in this situation?
P.S.: One additional detail – I don’t know if it makes any difference: My WP site uses a subdirectory of a domain as its home URL, like https://www.example.com/mysite
. So the above mentioned link is actually https://www.example.com/mysite/motive/landscape
.
Is this achievable without coding? If coding is need, what files will need to be created to get the loop integrated in the custom taxonomy/post type pages?
Thanks
]]>I’ve spent several days googling this and searched here too with no joy. I’m using Genesis with a custom child theme based on Genesis Sample, posting here as this is a WP issue I think. My PHP skills are beginner/improver level at best.
I’ve set up a CPT and 2 custom taxonomies for it (both categories, no tags) in a basic plugin, with a single-cpt and an archive-cpt template. The taxonomy links have a template redirect to use the archive- template. The CPTs generally work as intended, except…
The 2 categories are displayed/linked in the entry-meta/post footer, but there’s a problem with the resulting links. The first category links to the correct archive (which is using the archive-cpt template as intended), but the second category – despite the permalink being correct e.g. website/taxonomy2/term – takes me to the blog page, using index.php as the template.
Is this a permalink problem? I’ve flushed the permalinks many times, no difference. It is producing the right path, so probably not this.
Is it a template problem? I can’t see how it would be as both taxonomies are essentially identical in the way they are registered, both were added at the same time, both are redirected to the same template and both work in all respects except this. The permalink for the second category is correct so the redirect is working.
I’m confused as I’ve used a very similar setup elsewhere with no issues (different theme and slightly different implementation).
Any help much appreciated, even just the right thing to search for would help, I’m not sure what the problem is. Happy to post code excerpts but I’m not sure what is relevant to this yet. All plugins, themes etc. are up to date.
Many thanks.
]]>I’ve developed some code for a custom post type archive that will output the custom taxonomy associated with the custom post type and, if there are posts, list the post titles with links to that post. If there are no posts in that custom taxonomy, the code invites the member to add content to that custom taxonomy.
Here’s a link to my code: https://pastebin.com/mtAwUkVT
The code works but there is something that is unexpected which I just can’t figure out. The post ID is displaying above the list item and I’m not instructing the code to do that. Clearly, I need the post ID to retrieve the permalink and title of the post but I do not need it to display on the page.
I haven’t finished styling the page yet but here’s a link to a screenshot showing anyone reading what I mean:
https://screencast.com/t/zN0ajUAhU
I know it is probably something silly that I’ve overlooked and I’m hoping fresh eyes can help me get rid of the unwanted output.
Thanks, in advance, for any assistance.
The code used to register these is this: https://pastebin.com/yJ9XHCDk
I have an archive movie page working using the following code in archie-movie.php:
<?php get_header(); ?>
<div id="middle" class="clearfix">
<div id="inner">
<div id="content" class="<?php echo $bw; ?>">
<?php get_template_part( 'part-genrenav'); ?>
<div id="pageHead">
<?php global $post; if(is_archive() && have_posts()) :
if ( is_post_type_archive() ) { ?>
<h1><?php post_type_archive_title(); ?></h1>
<?php } ?>
<?php endif; ?>
</div>
<div class="posts clearfix">
<?php get_template_part( 'part-pagination'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'part-movie'); ?>
<?php endwhile; ?>
<?php get_template_part( 'part-pagination'); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Taxonomy.php
I’ve created a taxonomy.php (and a taxonomy-genre.php and so on). Taxonomy.php is being called correctly here, but the loop in that template returns nothing. I’ve been back and forth through dozens of articles, but can’t seem to figure it out.
Currently, my taxonomy.php file is made up of this, as you can see it isn’t much different than they archive-movie.php file above. I just can’t figure out why it doesn’t work:
<?php get_header(); ?>
<div id="middle" class="clearfix">
<div id="inner">
<div id="content">
<div id="pageHead"><h1>Taxonomy Archive</h1></div>
<div class="posts clearfix">
<?php get_template_part( 'part-pagination'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part( 'part-movie'); ?>
<?php endwhile; ?>
<?php get_template_part( 'part-pagination'); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
]]>The site I run has two custom post types. One of them is ‘portfolio-category’ (slug).
I wanted to have a page where I can show only the particular custom posts categorised by the custom taxonomy (a set of categories) for that post type. I looked everywhere but couldn’t find anything so I ‘hacked’ around and found one very silly way to make it work.
<h3>Weddings</h3>
<ul>
<?php
global $post;
$args = array( 'post_type' => 'portfolio', 'portfolio-category' => 'wedding' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li class="_archive"><a href="<?php the_permalink(); ?>" class"_archivelink"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
Basically, I repeated this snippet for each category including the heading (static). Stupid, I know but not having learned PHP from ground up I have no idea how to make this more elegant. I can only guess that I could use Loop function.. That’s as far as I went and I’m giving up after spending pretty much all day on this.
I’m sure there are experts out there who could advise me what to do?
Thank you for your kind help.
]]>Following the example in the Codex, I’ve set up pagination for use with my custom post type/custom taxonomy archive (all books in the given series). However, it behaves rather strangely: the last page (correctly calculated and linked) gives me a 404.
This is my code for pagination:
echo paginate_links(
array(
'base' => get_pagenum_link() . '%_%',
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $myBookTitles->max_num_pages
)
);
And this it my query:
$args = array(
'posts_per_page' => 9,
'paged' => get_query_var('paged'),
'post_status' => 'publish',
'post_type' => 'book',
'meta_key' => 'datepublished',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'series',
'field' => 'slug',
'terms' => $wp_query->query_vars['term']
)
)
)
);
$myBookTitles = new WP_Query($args);
This works for pages 1 to n – 1. The resulting permalink structure is /series/name/n.
If, on the other hand, I change the query and the pagination to use the query_var ‘page’ instead of ‘paged’ (and thus bypass rewriting), it works as expected.
Any thoughts and pointers would me much appreciated.
Thank you.
]]>I have a custom taxonomy for certain posts. Unfortunately, their archive pages do not have the grid, and there’s no option to select those in the admin panel.
Would you have a tip for me how I can include the archive pages for my custom taxonomies?
Thank you,
Anne
https://www.ads-software.com/extend/plugins/genesis-grid-loop/
]]>I have a site with several custom taxonomies and I need a conditional that can tell me if i’m on an archive page that is a sub page of a specific custom taxonomy page
for example:
https://somatosphere.net/transcriptions/books displays the custom taxonomy term transcriptions of the custom taxonomy spheres and then subsequently all the posts with category books. So all posts with transcriptions and books.
is_tax(term,tax) returns false for this page, as it is technically a category_page.
is_archive and is_category return true.
so what I seemingly need is an is_tax_sub_archive() or something like that.
I have a function that can tell me if one (or more) of the posts on the page has a specific custom taxonomy term, but that will return true even if I am on a general category page like https://somatosphere.net/books, that happens to show one post with the term transcriptions.
I can just pull transcriptions from the uri I guess and make that a conditional, but that seems such a hack. Upon typing this I’d figure it is a solution to my problem, so I did it:
function is_tax_sub_archive($term){
$the_uri = $_SERVER[‘REQUEST_URI’];
if (strpos($the_uri,$term)) {
return true;
}
return false;
}
However, there might be nicer solutions out there, as this will also return true for posts with the term in their title (which in my case is not a bad thing, but with a more common term name this would not work anymore).
Thanks for helping me think through above issue,
Maarten
]]>Is this possible?
]]>