- This topic has 5 replies, 2 voices, and was last updated 4 years ago by
Tom.
-
AuthorPosts
-
February 25, 2019 at 6:57 am #820923
Cristina
Hi there,
This is more a question on how to attack a problem then it is theme support / though..my main concern is how it will look on the theme.
I’ve added a custom post type – Projects – that has a custom taxonomy – Group.
Is it possible to separate the behavior (render) of custom taxonomies on the theme?See that makes sense to me, Projects are organized in groups.
But lets say i want to filter several projects of the same author?I’ve added custom fields to my ”project post type”. Say author, year, location…
If i want to filter by author, is that possible? And will it appear next to the category of Group?
See image https://screenshots.firefox.com/PHxZxrLBmMyF5s9l/null please, i don’t want author to be a folder icon next to tags.. but that is what will happen if i say author is a category, right?
So what is the logic in wp behind this problem? I’m sure i’m missing somethingI do hope the image is more clarifying then my explanation.
https://screenshots.firefox.com/PHxZxrLBmMyF5s9l/null
Any help will be most appreciated. Thank you.
GeneratePress 2.2.2GP Premium 1.7.8February 25, 2019 at 2:06 pm #821379Tom
Lead DeveloperLead DeveloperHi there,
So, are you wanting to view all posts by an author (which is a custom field), regardless of the category?
Not sure I understand 100%.
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 25, 2019 at 2:54 pm #821410Cristina
Yes, that is it. But for author to appear more or less where it is, not on footer with other categories.
Sorry about 3 poor explanation.February 25, 2019 at 5:29 pm #821504Tom
Lead DeveloperLead DeveloperShould be possible, I think. We need a page to write the query to, though. For example, where are all your posts displayed? On the
/news
page?You could try this:
add_action( 'pre_get_posts', function( $query ) { if ( is_admin() ) { return $query; } if ( is_home() ) { if ( isset( $_GET['author'] ) ) { $query->set( 'meta_key', 'author' ); $query->set( 'meta_value', esc_attr( $_GET['author'] ) ); } } return $query; } );
To get this to work, you’d need to set your link up like this:
yoursite.com/news?author=author_name
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 27, 2019 at 6:34 am #823239Cristina
The custom post type is ‘Project’. The are displayed using elementor, in site.pt/work/ in a portfolio element… Not sure if this is what you mean. I’m far from getting this, and probably is best to point me in the direction of an experienced php developer :/
<?php /** * The template for displaying single projects. * * @package GeneratePress */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_article_schema( 'CreativeWork' ); ?>> <div class="inside-article"> <?php /** * generate_before_content hook. * * @since 0.1 * * @hooked generate_featured_page_header_inside_single - 10 */ do_action( 'generate_before_content' ); ?> <header class="entry-header"> <?php /** * generate_before_entry_title hook. * * @since 0.1 */ do_action( 'generate_before_entry_title' ); if ( generate_show_title() ) { the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); } /** * generate_after_entry_title hook. * * @since 0.1 * * @hooked generate_post_meta - 10 */ do_action( 'generate_after_entry_title' ); ?> </header><!-- .entry-header --> <?php /** * generate_after_entry_header hook. * * @since 0.1 * * @hooked generate_post_image - 10 */ do_action( 'generate_after_entry_header' ); ?> <div class="entry-content" itemprop="text"> <?php the_content(); ?> <div class="Rtable Rtable--2cols Rtable--collapse"> <div style="order:0;" class="Rtable-cell "> <h4>Client: <?php the_field('client'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Area: <?php the_field('area'); ?> m2</h4> </div> <div style="order:0;" class="Rtable-cell "> <h4>Year: <?php the_field('year'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Location: <?php the_field('location'); ?></h4></div> <div style="order:0;" class="Rtable-cell "> <h4>Author: <?php the_field('author'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Builder: <?php the_field('builder'); ?></h4></div> </div> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ), 'after' => '</div>', ) ); ?> </div><!-- .entry-content --> <?php /** * generate_after_entry_content hook. * * @since 0.1 * * @hooked generate_footer_meta - 10 */ do_action( 'generate_after_entry_content' ); /** * generate_after_content hook. * * @since 0.1 */ do_action( 'generate_after_content' ); ?> </div><!-- .inside-article --> </article><!-- #post-## -->
this is all my content-project.php
the_content(); ?> <div class="Rtable Rtable--2cols Rtable--collapse"> <div style="order:0;" class="Rtable-cell "> <h4>Client: <?php the_field('client'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Area: <?php the_field('area'); ?> m2</h4> </div> <div style="order:0;" class="Rtable-cell "> <h4>Year: <?php the_field('year'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Location: <?php the_field('location'); ?></h4></div> <div style="order:0;" class="Rtable-cell "> <h4>Author: <?php the_field('author'); ?></h4> </div> <div style="order:1;" class="Rtable-cell"> <h4>Builder: <?php the_field('builder'); ?></h4></div> </div>
Iknow it’s not pretty, but thats how i’ve solved it…
this is the part, where, instead of displaying only ‘the field value’,
<?php the_field(‘author’); ?>
i’d like for users to be able to click that field value (as a link) to query other ‘projects’ for same value of field.So i add that function instead of «the_field» right ? Sorry for the trouble, i’d like to understand that’s all. And if i don’t i’ll just have to ask someone to do it for me.. TY
February 27, 2019 at 4:52 pm #823902Tom
Lead DeveloperLead DeveloperWhat you’re trying to do is actually super complex, so it might be best to hire a developer.
What my code does is check for a query string in your URL. If the query string has the author, it will slip into the query and tell it to only display posts from that author.
So in your template, you would try replacing:
<?php the_field('author'); ?>
With:
<a href="<?php echo home_url( 'news' ); ?>?author=<?php the_field('author'); ?>"><?php the_field('author'); ?></a>
Of course, there are a ton of variables here that can cause my code not to work. It’s just a proof of concept that will likely need some tweaking.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.