Genesis2.0 and Portfolio custom post type

Community Forums Forums Design Tips and Tricks Genesis2.0 and Portfolio custom post type

This topic is: not resolved

This topic contains 4 replies, has 2 voices, and was last updated by  David Chu 1 year, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #58860

    thoughtwell
    Participant
    Post count: 12

    I recently added a custom post-type to my site using this method, here:

    WriteNowDesign

    I was doing it the ‘old’ way but it wouldn’t work w/ Genesis 2.0

    Pat’s newer method at the link, above, worked pretty well. I did change a few things, mostly to use this as a product-catalog, so I changed some classes and function names, accordingly.

    I want to know how to sort these by order. I’ve read a bit on WP_Query and I spent about 8 hours working with different possibilities, but I couldn’t get the to sort. I changed ‘order’ and even set ‘order’ as a custom field, but no dice. My site is hosted locally, so I can try to post some code, but I just wanted to know if anyone has any experience in getting posts to sort using something similar to the portfolio custom post type that many genesis themes use. I am using the vanilla genesis theme w/ my own custom child theme.

    #58886

    David Chu
    Participant
    Post count: 1395

    Hi,
    I’m not sure exactly what you coded, but I have a couple thoughts based on what you said above.

    You’ll want to be using “orderby”, not only “order”, although order could be set to ASC or DESC. You’ll need to define which field will be used for “orderby”. And if you’re sorting on a custom field, there’s something extra, you’ll also need to define “meta-key” and then your orderby will be “meta-value”, just as in this example taken from WP_Query central. :-)

    [php]
    $query = new WP_Query( array ( ‘post_type’ => ‘product’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘price’ ) );
    [/php]

    Good luck, D


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #58898

    thoughtwell
    Participant
    Post count: 12

    Here is what is contained within my archive-product-categories.php page before trying to do the sorting filter w/ WP_Query:

    <?php
    /**
     * The custom product-categories post type archive template
     */
    
    /** Force full width content layout */
    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
    
    /** Remove the post info function */
    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    
    /** Remove the post content */
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    
    /** Remove the post image */
    remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
    
    /* Add Product Category Title */
    
    add_action('genesis_before_content', 'summit_productspg_title');
    
    function summit_productspg_title() { ?>
        <header class="entry-header porthead"><h1 class="entry-title" itemprop="headline">Home Medical Equipment Products</h1></header>
    <?php }
    		/** Add the featured image after post title */
    		add_action( 'genesis_entry_header', 'summit_productcat_grid' );
    		function summit_productcat_grid() {
    			if ( has_post_thumbnail() ){
    				echo '<div class="productcat-featured-image">';
    				echo '<a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">';
    				echo get_the_post_thumbnail($thumbnail->ID, 'product-categories' );
    				echo '</a>';
    				echo '</div>';
    	}
    }
    
    /** Remove the post meta function */
    remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    
    genesis();
    

    Here is what I have tried so far:

    <?php
    /**
     * The custom product post type archive template
     */
    
    /** Force full width content layout */
    add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
    
    /** Remove the post info function */
    remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
    
    /** Remove the post content */
    remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
    
    /** Remove the post image */
    remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
    
    /* Add Product Category Title */
    
    add_action('genesis_before_content', 'summit_productspg_title');
    
    function summit_productspg_title() { ?>
        <header class="entry-header porthead"><h1 class="entry-title" itemprop="headline">Home Medical Equipment Product Categories</h1></header>
    <?php }
    
    // The Query
    
    $args = array(
        'meta_key' => 'order',
        'orderby' => 'meta_value',
        'order' => 'DES'
    );
    
    $query = new WP_Query( $args );
    
    // The Loop
    if ( $query->have_posts() ) {
    	while ( $query->have_posts() ) {
    		$query->the_post();
    		echo add_action( 'genesis_entry_header', 'summit_productcat_grid' );
    		function summit_productcat_grid() {
    			if ( has_post_thumbnail() ){
    			echo '<div class="productcat-featured-image">';
    			echo '<a href="' . get_permalink() .'" title="' . the_title_attribute( 'echo=0' ) . '">';
    			echo get_the_post_thumbnail($thumbnail->ID, 'product-categories' );
    			echo '</a>';
    			echo '</div>';
    			}
    		}
    	}
    }
    
    /** Remove the post meta function */
    remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    
    genesis();
    

    I don’t know if it maybe has something to do w/ there being a key and value both set to ‘order’ (I’m really in the infancy of my php skillset). Also, since this is a custom post type archive file, is it really necessary to set the post_type? Well, I went ahead and did it anyhow, but it was still broken. Basically, making these edits breaks the page/gets me errors.

    One of the things that confuses me is meta_key. If the ‘order’ field is natively set in the post attribute panel, it’s technically not a custom field I have set up, per se. However, may it very well be that it is? I wouldn’t think so, since I didn’t actually set up a custom field in the post, but rather just input numerical values under the order field shown in the attributes panel.

    #58909

    thoughtwell
    Participant
    Post count: 12

    So, before my loop, I just put:

    query_posts(array('post_type'=>'product-categories','orderby'=>'menu_order','order'=>'ASC'));
    

    Now, it seems to be working how I want it to. I’m not sure if this is the most current, semantic way to do this for 3.6 and Genesis 2.0, but it’s doing what I want it to, so if anyone has any better suggestions using WP_Query, I’m all ears, but for now this seems to work.

    #59033

    David Chu
    Participant
    Post count: 1395

    Glad that’s working for you. One FYI – for a descending sort you need to specify “DESC” rather than “DES”.

    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.