[Support request] CPT, taxonomy logic and theme location

Home Forums Support [Support request] CPT, taxonomy logic and theme location

Home Forums Support CPT, taxonomy logic and theme location

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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 something

    I do hope the image is more clarifying then my explanation.

    https://screenshots.firefox.com/PHxZxrLBmMyF5s9l/null

    Any help will be most appreciated. Thank you.

    #821379
    Tom
    Lead Developer
    Lead Developer

    Hi 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 🙂

    #821410
    Cristina

    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.

    #821504
    Tom
    Lead Developer
    Lead Developer

    Should 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

    #823239
    Cristina

    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

    #823902
    Tom
    Lead Developer
    Lead Developer

    What 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.