• 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

Genesis Custom Loop

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 › Genesis Custom Loop

This topic is: resolved
  • This topic has 19 replies, 5 voices, and was last updated 9 years, 4 months ago by Summer.
Viewing 20 posts - 1 through 20 (of 20 total)
  • Author
    Posts
  • July 16, 2014 at 6:12 am #114509
    emmtre
    Participant

    What's the correct syntax to use several category names ('blog' or 'quote') as argument?

    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'site_front_page' );
    function site_front_page() {
        global $paged;
        global $query_args;
        $args = array(
            'category_name' => 'blog',
            'paged' => $paged,
        );
        genesis_custom_loop( wp_parse_args( $query_args, $args ) );
    }
    genesis();
    July 16, 2014 at 6:23 am #114513
    Genesis Developer
    Member

    try this way

    'category_name' => array('blog','quote','video')


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

    July 16, 2014 at 6:44 am #114516
    emmtre
    Participant

    Thanx but that didn't work. Here is the php error code for the second category. The first category works though.

    Warning: urlencode() expects parameter 1 to be string, array given in /public_html/wp-includes/formatting.php on line 3690

    July 16, 2014 at 8:54 am #114533
    marybaum
    Participant

    Could you do a Boolean there?

    'category_name' => 'blog' || 'quote' || 'video',

    I'm asking as much as suggesting. I don't know if a Boolean counts as a string.

    Another thing might be to declare a variable:

    $catname = 'blog' || 'quote' || 'video';

    then do

    'category_name' => $catname,

    I have no idea, without trying them myself, if those would work.

    Guess I oughta Google argument syntax. 😉


    Sharing the good news about the wonders of modern CSS and the split-step. Either one should get you moving fast. 😀

    July 16, 2014 at 11:35 am #114550
    Brad Dalton
    Participant

    Depends on how you use them http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters


    Tutorials for StudioPress Themes.

    July 16, 2014 at 3:28 pm #114570
    emmtre
    Participant

    Brad,

    I't trying to use 'category_name' => 'blog', 'quote', as I have done in the past but now for a custom front-page template in a Genesis child theme but only posts with the first category with the slug 'blog' is displayed. The strange thing is that it seems to work with a page and the Genesis built-in blog template but not with my custom front-page template. And according to Bill Erickson the syntax is correct. Any ideas? Has something changed in WordPress or Genesis lately?

    http://www.billerickson.net/code/wp_query-arguments

    July 16, 2014 at 3:38 pm #114573
    emmtre
    Participant

    This is really strange. When I use the argument and the plus "+" operator for displaying posts that have both the 'blog' and 'quote' category all posts that have either the 'blog' or 'quote' category is displayed instead? There must be a logical error somewhere in the latest Genesis version?

    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'site_front_page' );
    function site_front_page() {
        global $paged;
        global $query_args;
        $args = array(
            'category_name' => 'blog' + 'quote',
            'paged' => $paged,
        );
        genesis_custom_loop( wp_parse_args( $query_args, $args ) );
    }
    genesis();
    July 16, 2014 at 4:09 pm #114576
    Brad Dalton
    Participant

    Have you tried pre_get_posts to exclude categories? This is the most efficient way to alter the loop.


    Tutorials for StudioPress Themes.

    July 16, 2014 at 4:55 pm #114583
    Summer
    Member

    Are you trying to display posts that are in either category or only in both categories?

    The correct syntax for queries for posts in multiple categories should be:

    'category__and' => array( 2, 6 )

    You have to use the category ID, not the slug for this one.

    from http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    July 17, 2014 at 12:59 am #114616
    emmtre
    Participant

    I have done some more testing and can only conclude that the genesis_custom_loop doesn't work with the latest versions of Genesis and WordPress.

    You should be able to add categories by adding them to the end of the parameter list (separated by commas) with 'cat' and 'category_name' as stated in the WordPress Codex.

    When used with the built-in Genesis blog template and custom fields it does work as expected with several categories but not with a custom front-page.php or home.php template.

    The 'cat' and 'category_name' only accept the first category in a list (separated by commas) due to some problem in WordPress with the format and syntax for integers and strings as argument.

    From the php error code it seems like WordPress doesn't accept integers or strings anymore in the parameter list du to some internal format and sanitize functions in WordPress.

    But 'category__and' and 'category__in' does work as expected with several categories since the parameter list is in an array with all the category id's separated by commas.

    Another problem I also discovered with the genesis_custom_loop was that the sticky posts didn't work in the custom front-page.php template.

    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    I have not used pre_get_posts to exclude categories before in a template but I will give it a try. Thanx for the suggestion and link.

    July 17, 2014 at 8:54 am #114658
    Summer
    Member

    I think your testing criteria may be flawed, because a number of folks here (including me) are still using genesis_custom_loop just fine. 🙂

    Are you sure exactly what $query_args contains when being called in this function, before squishing it together with your new $args?

    Just for grins, replace your custom loop call with this: genesis_custom_loop ( $args ); and see what happens.

    also, 'cat' requires the category ID (a number), and 'category_name' takes the slug (a string), not the actual category name. If WordPress even casually mentioned that they would stop accepting those parameters, the Internet would have crashed from the number of people crying out simultaneously in rage & retribution 🙂

    So if you want to use category_name, I think you need this:

    category_name => 'array( 'blog' ,' quote' )

    or

    category_name=> array( 'blog'+'quote' )

    I should go test that, shouldn't I?


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    July 17, 2014 at 10:59 am #114673
    emmtre
    Participant

    Summer, yes you should definitely go testing yourself since you can't use an array with 'cat' or 'category_name'... Then you can try to add categories to 'cat' or 'category_name' just by adding them separated by commas as stated in the WordPress Codex. And I sure do know that 'cat' requires the category ID (number) and 'category_name' the slug (string). My testing environment is a freshly installed WordPress 3.9.1 and Genesis 2.1.2.

    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'site_front_page' );
    function site_front_page() {
        global $paged;
        global $query_args;
        $args = array(
            'category_name' => 'blog', 'quote', 'video',
            'paged' => $paged,
        );
        genesis_custom_loop( wp_parse_args( $query_args, $args ) );
    }
    genesis();
    July 17, 2014 at 11:26 am #114682
    Summer
    Member

    You have a syntax problem with the comma separated values, which is what I was trying to resolve.

    The array parameters are always done in pairs, "variable => value," but since you have in $args a list of "variable => value, value, value," it cannot figure out what you want, so it takes the first pairing and dumps the rest.

    You need to use category__in or category__and and the category IDs

    This works:

    function site_front_page() {
        global $paged;
        $args = array('category__in' => array (1, 41), 'paged' => $paged);
        genesis_custom_loop( $args );
    }

    I even tested it in a front-page.php template.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    July 17, 2014 at 11:45 am #114685
    Genesis Developer
    Member

    I tried this code and it is working. i am getting all posts from three categories:

    add_action( 'genesis_loop', 'site_front_page' );
    function site_front_page() {
        global $paged;
        $args = array(
            'cat' => '1,7,10',
            'paged' => $paged
        );
        genesis_custom_loop(  $args );
    }
    

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

    July 17, 2014 at 11:46 am #114686
    emmtre
    Participant

    Yes but you should be able use comma separated values as stated in the WordPress Codex and it does work with the Genesis built-in blog template but not with the front-page template.

    And you can use 'category__in' instead which accept an array of values but then you have to change all categories since this doesn't show any posts from sub-categories (children).

    I was just qurious about how others have solved this issue since it will require a lot of manual work to change all categories for all posts.

    And it look like genesis_custom_loop_args will accept comma separated values for' category_name' but they are stripped by some internal format and sanitize functions in WordPress.

    I will find a solution with genesis_custom_loop since I need the front-page template to also be able to display widget areas with other post categories like 'news' on the front page

    Thanx for the help!

    July 17, 2014 at 11:49 am #114688
    emmtre
    Participant

    Thanx genwrok I have not tested with singel quotes outside the category IDs.

    'cat' => '1,7,10',

    July 17, 2014 at 11:49 am #114689
    Genesis Developer
    Member

    I think that main issue is here :

    global $query_args; and wp_parse_args( $query_args, $args ). You do not need to use the 'wp_parse_args' function. genesis_custom_loop is already using this function.


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

    July 17, 2014 at 11:50 am #114690
    Genesis Developer
    Member

    those are my category IDs. I just tested on my dev site and it is working,


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

    July 17, 2014 at 12:00 pm #114694
    emmtre
    Participant

    And the winner is genwrock! You had to place the single quotes outside the comma separated values. Many thanx!

    'category_name' => 'blog, quote, video',

    July 17, 2014 at 1:06 pm #114711
    Summer
    Member

    Regarding the commas/quotes, If it had been a snake, it woulda bit us 🙂

    Also, you can have the custom loop and the widget spaces in your front-page.php... it's not an either/or thing.

    Good luck!


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

  • Author
    Posts
Viewing 20 posts - 1 through 20 (of 20 total)
  • The topic ‘Genesis Custom Loop’ is closed to new 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