- This topic has 10 replies, 2 voices, and was last updated 7 years, 6 months ago by
Tom.
-
AuthorPosts
-
September 12, 2018 at 2:51 pm #675822
Jorge
Hello, I have created a Custom Post Type (propiedades) for a real estate website.
I have also created archives-propiedades.php placed in child theme and I want the title “Archives: propiedades” not to be visible and to be able to place another new title, but I do not know where to change it.
I also want to show archives-propiedades.php with a random order so that all the “propiedades” have equal probability of being up on each page load that is in masonry style.
Could you please tell me from where or how can I modify these things?
Thank you very much in advance
JorgeSeptember 12, 2018 at 7:47 pm #675922Tom
Lead DeveloperLead DeveloperHi there,
For the title, do this:
add_filter( 'get_the_archive_title', function( $title ) { if ( is_post_type_archive( 'propiedades' ) ) { return 'Your title here'; } return $title; } );For the random order, try this:
add_filter('pre_get_posts', function( $query ) { if ( ! is_admin() && $query->is_main_query() && is_post_type_archive( 'propiedades' ) ) { $query->set('orderby', 'rand'); } return $query; } );Let me know if this helps or not 🙂
September 13, 2018 at 11:58 am #676619Jorge
Thank you very much Tom
The title change went OK
The randomized unfortunately did not work, returns HTTP ERROR 500
Could you try to check it? please
JorgeSeptember 13, 2018 at 1:34 pm #676686Jorge
Ready done! there was no closing on line 7 );
of the code to randomize
Thanks, I owe you a beer!
JorgeSeptember 13, 2018 at 7:00 pm #676815Tom
Lead DeveloperLead DeveloperAh, sorry about that! Glad it’s working 🙂
October 3, 2018 at 5:09 am #692315Jorge
Template Archive with all post types together
Hello, excuse this reopening but it is to complete. I have several Post Types, and I want to put them all together in an “archive” type template, I know how I show type by type, but I do not know how to show them all together type1, type2, etc and in random masonry format.
Thank you so much
Jorge
GP Premium 1.7.2October 3, 2018 at 10:06 am #692674Tom
Lead DeveloperLead DeveloperHi there,
So you want one archive template that displays multiple post types? Do you have a custom archive template added to your child theme?
October 3, 2018 at 11:09 am #692723Jorge
No Tom, I do not have templates attached to my child theme, I think they use the archive.php of the original theme.
JorgeOctober 3, 2018 at 8:58 pm #692981Tom
Lead DeveloperLead DeveloperSo you’d likely need to create a custom template file along with a custom query that calls multiple post types.
get_posts()is the function you would use to query the multiple post types.October 4, 2018 at 4:21 am #693184Jorge
I understand, could you advise me? which template.php should I take as a model to introduce this function get_post () for displaying all the post (I guess it can be archive.php, but I’m not sure)
My knowledge of php are very few.
Thank so much. JorgeOctober 4, 2018 at 4:28 pm #693764Tom
Lead DeveloperLead DeveloperIt depends which archive you’re trying to target.
All archives would be
archive.php. Others would be named differently: https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-post-typesThe examples here might help: https://wordpress.stackexchange.com/questions/256428/how-to-show-posts-from-multiple-post-types-in-a-single-loop-and-display-them-se
-
AuthorPosts
- You must be logged in to reply to this topic.