Rachel Cherry
Forum Replies Created
-
I discovered, recently, that if you’re using anything less WP 3.3, the settings page help tab throws an error. I have added a fix for CPT-onomies version 1.0.3, which should hopefully be available later today.
If you’d like me to go ahead and send you the fix, contact me and I’ll email you the file.
Forum: Plugins
In reply to: [Plugin: CPT-onomies]Customising the back end – wish listHey!
Just wanted to let you know I just finished adding “sorting” and “filtering” to admin edit posts screen =)
I hope to push out the update later this week. woot!
Hey!
- I have added “quick edit” functionality to the list. I can’t promise it will be out in the next version (which will be out later this week) but I’ll try to get it up and running soon!
- I’m experience-less in automatically populating subnavs with custom post types but if I find anything, I’ll let you know.
Ok. I think I found the problem. It will be fixed in the next update but I went ahead and emailed you the new code.
The problem lied in wp_get_object_terms() having an issue with multiple object IDs.
If anyone else stumbles upon this problem before version 1.0.3, look for the following code in the wp_get_object_terms() function in the cpt_onomy.php file:
// this allows for a string with one object id or an array with multiple object ids if ( !is_array($object_ids) ) $object_ids = array($object_ids); $object_ids = array_map('intval', $object_ids);
and replace it with:
// this allows for a string with one object id or an array with multiple object ids if ( !is_array( $object_ids ) ) { $object_ids = str_replace( ', ', ',', $object_ids ); $object_ids = explode( ',', $object_ids ); } $object_ids = array_map( 'intval', $object_ids );
Well, crap. I apologize. I didn’t remove it either after I was done testing and it, too, put me back at the beginning.
Let me dig around some more…
Thanks for the email and the code!
I used your code on my test site and saw that it was doing the same for me. It was only showing the terms for the first post.
After a little digging, I discovered it was a caching problem so I flushed my cache. I just placed the following code at the top of my archive-actors.php file:
wp_cache_flush();
That fixed the problem for me, just be sure to remove the function after you’ve run the page. The function only needs to be run once.
Oh, and FYI: using the WP function get_the_term_list() does work BUT where its supposed to link to the term’s archive page, it links to the custom post type’s single post page because of some conflicts with taxonomy and custom post type rewrites.
If you prefer the single post link, then ignore this part. But if you would prefer the link to the term’s archive page, you can use the CPT-onomy get_term_link(). All you have to do is add ‘$cpt_onomy->’ to the front of the function:
<p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'directors', '<h6>Directors:</h6> ', ', ', '' ); ?></p> <p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'events', '<h6>Events:</h6> ', ', ', '' ); ?></p> <p><?php echo $cpt_onomy->get_the_term_list( $post->ID, 'productions', '<h6>Artists:</h6> ', ', ', '' ); ?></p>
Hey! Thanks for the hugs =)
Can you send me your archive-actors.php file? Contact me and I’ll respond pretty quickly so you can attach the file.
If you keep to just the one taxonomy and use the parameters ‘taxonomy’ and ‘term’ and ‘post_type’, WordPress stores the information in $wp_query. The following will show you the info:
global $wp_query; echo "<pre>"; print_r( $wp_query ); echo "</pre>";
Because these are default WordPress parameters, WordPress will even redirect you to the right template. It takes these parameters and recognizes that you are trying to show a taxonomy archive page and, if you have an archive.php file, it will use the archive.php template. Otherwise it will follow the template hierarchy.
WordPress will even setup the Loop to query the correct posts.
Once you’ve got your template file setup, you can access $wp_query to retrieve your URL parameters to then use, at will, to modify the Loop query as you see fit.
If you want to add in a second taxonomy, you’ll most likely have to add your own custom query variable, i.e. ‘taxonomy2’ or something like that, and register your custom query variable so $wp_query will recognize the parameter in the URL. Then, in your template file, access $wp_query to retrieve your parameter’s info to then use at will to adjust the Loop query.
Make sense?
Use the following code to register a custom query variable:
add_filter( 'query_vars', 'register_custom_query_vars' ); function register_custom_query_vars( $vars ) { array_push( $vars, 'taxonomy2' ); return $vars; }
Let me know if you need any more help!
Ok. What you want is totally do-able but it’s going to take some customization on your part.
First off, you’re going to have to decide on your URL parameters. A simple solution might be to just add a taxonomy parameter that’s set to the taxonomy/CPT-onomy name, like so:
I have an ‘actors’ custom post type that is also a CPT-onomy so I would include the following parameters to define that I want to query posts that are tagged with the ‘actors’ taxonomy/CPT-onomy, more specifically are tagged with the ‘actors’ term ‘tom-hanks’.
https://mysite.com/?taxonomy=actors&actors=tom-hanks
These URL parameters could also mean that you want ‘actors’ post types who are tagged with the ‘actors’ CPT-onomy but since this is your custom setup, you can have it mean whatever you like. To avoid confusion, you might want to rearrange it like so:
https://mysite.com/?taxonomy=actors&term=tom-hanks
This URL actually prints/includes the archive template because WordPress understands this to be the parameters for a taxonomy term archive page.
You can add a post_type parameter to declare you only want particular post types who are tagged with the taxonomy term:
https://mysite.com/?post_type=movies&taxonomy=actors&term=tom-hanks
With me so far?
So now that we have that covered, the next step is deciding whether or not you’re fine with the page including the archive template or if you’d like WordPress to use another template (keep in mind that WordPress is not actually redirecting anything).
But if you’d really like WordPress to use your home page template, all it takes is a little trickery. Read over all of this and let me know if you want me to keep going.
Of course, now that I think about it some more, it makes sense that by defining $link as ” (which is empty), the printed link text would be empty (the function still prints the wrapper).
AND, as strange as it sounds, I can imagine instances where you might not want the link text so I’ll leave the setup as it is for now and update the documentation to make the $link parameter be required, unless you want the printed link text to be blank.
Thanks for your help in finding this little gem =)
Ok. I figured out the problem. It seems that you have to define both of the first 2 parameters, $format and $link, of the $cpt_onomy->previous_post_link() and $cpt_onomy->next_post_link() functions for the link to print correctly. The functions were finding the previous and next post information but because $link was ”, the printed link was empty.
The easy fix: define $link (just put the default which is ‘%title’).
I apologize for this oddity. I just copied and pastied the WordPress previous_post_link() and next_post_link() to create $cpt_onomy->previous_post_link() and $cpt_onomy->next_post_link() and this weirdness never crossed my mind.
I have updated the documentation to point out this issue and will “fix” this little bug for the next version.
I hope this fixes everything. Let me know if it doesn’t. Thanks!
Here’s my first question: is it actually redirecting? or just showing the post?
Example: On my demo setup, I have an ‘actors’ post type and an ‘actors’ CPT-onomy. When I type https://localhost/?actors=tom-hanks it doesn’t redirect BUT it does show the ‘actors’ template for the Tom Hanks’ post.
Let me look into this some and figure out the best solution. I’ll get back to you ASAP. Thanks!
It’s no problem. Yea, send me the URL for your test blog.
FYI: You don’t have to do global $cpt_onomy twice. Once, at the beginning, will do the trick =)
If you’re wanting the link for the next post that’s in the CPT-onomy ‘stories’, you have to use the CPT-onomy function: $cpt_onomy->next_post_link().
If you just wanted the next post link, you could use next_post_link() but, because defining a CPT-onomy to overwrite the default taxonomy ‘category’ is a custom feature that’s not available in the core WordPress function next_post_link(), I created a custom previous_post_link() and next_post_link() just for CPT-onomies.
These CPT-onomy functions do mirror the WordPress functions, however, and accept the same parameters with the exception of an additional parameter that lets you define with CPT-onomy you want to use:
global $cpt_onomy; $cpt_onomy->previous_post_link( '<strong>< %link</strong>', '', true, '', 'stories' ); $cpt_onomy->next_post_link( '<strong>< %link</strong>', '', true, '', 'stories' );
I’ve added previous_next_link() and next_post_link() to the CPT-onomies documentation if you need more information.