• 0

Flipper for Custom Post Types


Question

Posted · Report post

http://paste.pagelines.com/JXmB1ORq

 

This applies for WooCommerce, but also for any custom_post_type. 

 

In Flipper, the default allows us to choose a post_type.  Flipper does this by get_post_types, creates and array and then makes that array available to us in the drop down selection.  Let's say I want to set the post type, and then create the array of the taxonomy(ies) under that post type.  My drop down menu would then be populated with the taxonomy(ies) of this specific post type that I've set in my new section file.  

 

Now that we know what I want to do...

 

The documentation for "Select Taxonomy" (ref:  http://docs.pagelines.com/developer/dms-option-engine ) states:

"To create an option that allows users to select a taxonomy (i.e. category) for a specific post type, just use these attributes:"

 

and shows: 

$opts[] = array(
            'key'           => 'some_key',
            'type'          => 'select_taxonomy',
            'post_type'     => 'post' // the post type to grab taxonomies from
        );

Now that we've set that background up:  what is the "key" here?  Is the key my post_type or do I set the key somewhere else?  The default is set to "flipper_post_type".  

 

I've posted an attempt in pastebin above.  

 

Thanks in advance.

Share this post


Link to post
Share on other sites

4 answers to this question

  • 0

Posted · Report post

Yeah, but I'd rather not have to require the client to enter meta data for every custom post type.  If I set the post_type and know the taxonomy(ies) and slug(s) that I would like to show in the drop down, I should be able to create a new Flipper section, right?  Again, set the product so that the drop down becomes the available taxonomies or slugs.

 

Do I need to change the "key" element?  It's set to "flipper_post_type" in the default, so does this change or remain the same when creating new sections?

 

Thanks!

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I updated and cleaned up the file a bit:  http://forum.pagelines.com/pst/p/13-cza4mw/

 

I still need to get the categories of the custom_post_type to populate the drop down menu in the options.  

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I did try the shortcodes in the Flipper Meta section, just to see if I could specify the product category that I'm trying to target, but it didn't seem to work.  The I assume I can use the shortcodes from WooCommerce for this?

 

So, back to the dropdown of sub-catgeories in a custom Flipper Section, I just wanted to check to make sure I'm focusing on the right area of the functions here.  

 

Reference of terms that we are working with here:

 

(from URL string:  taxonomy=product_cat&tag_ID=55&post_type=product)

custom_post_type  = product

taxonomy = product_cat

slug = (determined by drop down selection, but looking here for 'certified' or term_ID of 55)  (which is the KEY that I was asking about earlier)

 

In my custom flipper section, this works: 

if($this->opt('flipper_post_type') == 'post'){
			$selection_opts[] = array(
				'label'			=> 'Post Category',
				'key'			=> 'flipper_category', 
				'type'			=> 'select_taxonomy', 
				'post_type'		=> 'post', 
				'help'		=> __( 'Only applies for standard blog posts.', 'pagelines' ),
			); 
		}
		
		elseif ($this->opt('flipper_post_type') == 'product') {
			$selection_opts[] = array(
				'label'			=> 'Product Category',
				'key'			=> 'flipper_category', 
				'type'			=> 'select_taxonomy', 
				'post_type'		=> 'product', 
				'help'		=> __( 'Only applies for products.', 'pagelines' ),
			); 

		}

It seems that farther down the file, the actual execution of the function takes place.  I've been unable to get the dropdown to display the sub-categories of the products.  Most recently I've referenced these articles to help, but to no avail:

 

How we would create a custom_post_type dropdown menu without Pagelines:  http://wordpress.stackexchange.com/questions/1236/custom-post-type-taxonomy-dropdown-menu

<?php $tax = get_object_taxonomies('TAXONOMY_NAME');
$taxterms = get_terms( $tax, 'orderby=count&offset=1&hide_empty=0&fields=all' );
?>

foreach ( $taxterms as $term ) { 
        echo '<option value="' . $term->slug . '" selected>' . $term->name . '</option>',"\n"; 
    } ?>

Checking difference between is_product_category and in_product_category (you can use 'has_term') http://wordpress.org/support/topic/plugin-woocommerce-excelling-ecommerce-is_product_category-vs-in_product_category?replies=4

Stackexchange for getting top level parent for WooComm:  http://wordpress.stackexchange.com/questions/24794/get-the-the-top-level-parent-of-a-custom-taxonomy-term

WooCommerce is_product: http://docs.woothemes.com/wc-apidocs/function-is_product_category.html

And I checked out Ellen's WooCommerce for Pagelines sections:  https://github.com/bearded-avenger/pagelines-woocommerce/blob/master/pagelines-woocommerce.php to see how she's calling product information. 

 

 

Just to be clear, the Products DO SHOW, but I want to filter the Products by category and allow the client to have this filtering ability.  

 

I know the function for regular post filtering is this:

if ('flipper_post_type' == 'post') {
		
		if( $this->opt('flipper_category') && $this->opt('flipper_category') != '' ){
			$cat = get_category_by_slug( $this->opt('flipper_category') ); 
			$the_query['category'] = $cat->term_id;
		}

but when I do something like this, it doesn't work:

}  elseif ('flipper_post_type' == 'product') {

		if( $this->opt('flipper_category') && $this->opt('flipper_category') != '' ){
			
			$term = has_term( 'flipper_category', 'product_cat' );
			
			$the_query['category'] = $term->term_id;
			
			}
		}

Thanks for any help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now