• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Making filters affect custom loop only

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Making filters affect custom loop only

This topic is: resolved

Tagged: custom loop, Custom Post Type, schema markup

  • This topic has 2 replies, 2 voices, and was last updated 7 years, 9 months ago by Graham.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • June 9, 2015 at 12:42 pm #155608
    Graham
    Member

    Think I'm missing something obvious here, yet am hoping someone can point me in the right direction ..

    I have a CPT ( vlhdir_entry) archive being displayed using a custom loop in archive-vlhdir_entry.php. As the entries are organisations and not blog posts, I filtered the mark up attributes to use the relevant schema mark up . Added using CPT conditional in the plugin file

    e.g.

    add_action( 'genesis_header', 'vlhdir_edits' ); 
    
    function vlhdir_edits() {
        
        if ( get_post_type() == 'vlhdir_entry' ) { 
           
             remove_filter( 'genesis_attr_entry', 'genesis_attributes_entry' );
            add_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' );
    
            // etc
    
        }
    
    }
    
    function vlhdir_attributes_entry( $attributes ) {
    
        $attributes['class']     = join( ' ', get_post_class() );
        $attributes['itemscope'] = 'itemscope';
        $attributes['itemtype']  = 'http://schema.org/Organization';
        return $attributes;
    
    }

    The trouble with this approach is that it applies the filter to all genesis_attr_entry on the page, including featured posts in sidebar.

    Noted when running page through structured data testing tool
    https://developers.google.com/structured-data/testing-tool/

    I need to restrict the filters to the custom loop entries only, or reset them to their defaults once the loop is complete.

    All pointers to the error in my ways or suggestions for alternative approach will be gratefully received 🙂

    Soft launch for client today, with incomplete data http://vegleatherhub.com/directory/


    My JustGiving page: https://www.justgiving.com/helping-graham-give

    June 9, 2015 at 12:50 pm #155611
    Genesis Developer
    Member

    Add this in your functions.php file

    add_action( 'genesis_entry_footer', 'gd_remove_vlhdir_filter', 20 );
    function gd_remove_vlhdir_filter() {
       remove_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' );
       add_filter( 'genesis_attr_entry', 'genesis_attributes_entry' );
    }

    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    June 9, 2015 at 4:37 pm #155632
    Graham
    Member

    OK great, thank you. That pointed me back on track

    As it stands, adding that to my existing code wouldn't work as hoped. I would end up with one Organisation and the rest being CreativeWorks ,

    Yet if I change the hook I use from genesis_header to genesis_before_entry .. then all good.

    i.e.

    add_action( 'genesis_before_entry', 'vlhdir_edits' ); 
    function vlhdir_edits() {
        if ( get_post_type() == 'vlhdir_entry' ) { 
            remove_filter( 'genesis_attr_entry', 'genesis_attributes_entry' );
            add_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' );
    
            // etc
    
        }
    }
    
    add_action(  'genesis_after_entry', 'vlhdir_remove_edits'  );
    function vlhdir_remove_edits() {
        if ( get_post_type() == 'vlhdir_entry' )  {
            remove_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' );
            add_filter( 'genesis_attr_entry', 'genesis_attributes_entry' );
    
            // etc
        
        }
    }

    My JustGiving page: https://www.justgiving.com/helping-graham-give

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble