Tag: custom post types

Clean up products and meta

DELETE FROM nwfa_wc_product_meta_lookup WHERE product_id IN (SELECT ID FROM nwfa_posts WHERE post_status = "trash");
DELETE FROM nwfa_postmeta WHERE post_id IN (SELECT ID FROM nwfa_posts WHERE post_status = "trash");
DELETE FROM nwfa_posts WHERE post_status = "trash";

Genesis 2 CPT Archive Settings

This is pretty cool.

Basically, you can add backend editing to the CPT archive with something like this:

function register_snippet_post_type(){
  
  // custom post type arguments
	$post_type_args = array(
		'label'		=> __( 'Snippet' ),
		'description'	=> __( 'Display code snippets' ),
		'public'	=> true,
		'show_ui'	=> true,
		'show_in_menu'	=> true,
		'has_archive'	=> true,
		'supports'	=> array( 'title', 'editor', 'genesis-cpt-archives-settings' )
	);
	
	// register the 'snippet' post type
	register_post_type( 'snippet', $post_type_args );
	
}

Move meta box above editor

add_action('admin_footer','subtitle_footer_hook');
function subtitle_footer_hook()
{
	?><script type="text/javascript">
	jQuery('#titlediv').after(jQuery('#_speaker_title_metabox'));
	jQuery('#_speaker_title_metabox').after(jQuery('#_speakers_metabox'));
	</script><?php
}

WPAlchemy Data Storage Modes

Be careful to do this to make data searchable. Out of the box WPAlchemy uses WPALCHEMY_MODE_ARRAY which is not very useful for meta searches!

$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/meta.php',
    'mode' => WPALCHEMY_MODE_EXTRACT,
    'prefix' => '_my_'
));

If you forget, use this:

    if ( ! function_exists( 'msd_convert_storage' ) ) :
            function msd_convert_storage($key,$prefix,$posttype) {
                    $args = array(
                        'numberposts'     => -1,
                        'post_type'       => $posttype,
                    );
                    $items = get_posts($args);
                    foreach($items AS $item){
                            $the_meta = get_post_meta($item->ID,$key);
                            $fields = array();
                            foreach($the_meta[0] AS $meta_key => $meta_value){
                                    $meta_key = $prefix.$meta_key;
                                    update_post_meta($item->ID, $meta_key, $meta_value);
                                    $fields[] = $meta_key;
                            }
                            update_post_meta($item->ID,$key.'_fields',$fields);
                            delete_post_meta($item->ID,$key);
                    }
            }
    endif;