Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
rileypaulsen / Post Formats via get_posts()
Last active December 19, 2015 13:09
query post formats in get_posts
$args = array(
'post_type'=> 'post',
'post_status' => 'publish',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-video' ),
'operator' => 'NOT IN'
@rileypaulsen
rileypaulsen / Retroactively Add Custom Fields
Last active December 19, 2015 13:09
retroactively add custom fields to existing posts
insert into wp_postmeta (post_id, meta_key, meta_value) select ID, '###FIELDNAME###', '1' from wp_posts WHERE post_type = '###POSTTYPE###'
@rileypaulsen
rileypaulsen / Show Drafts and Pending Review in Parent Dropdown
Last active December 19, 2015 13:09
show all drafts and pending review in the "parent" dropdown
add_filter( 'page_attributes_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );
add_filter( 'quick_edit_dropdown_pages_args', 'so_3538267_enable_drafts_parents' );
function so_3538267_enable_drafts_parents( $args ){
$args['post_status'] = 'draft,publish,pending';
return $args;
}
@rileypaulsen
rileypaulsen / Tax Query
Last active December 19, 2015 13:09
taxonomy query for get_posts()
'tax_query'=> array(
array(
'taxonomy' => 'decade',
'field' => 'id',
'terms' => $decadesArray,
'operator' => 'NOT IN'
)
)
@rileypaulsen
rileypaulsen / Update Term Count on Admin Term Management Page
Last active December 19, 2015 13:09
update the term count on admin term management page
$taxs = get_taxonomies();
foreach($taxs as $tax){
$args = array(
'hide_empty'=> false,
);
$terms = get_terms($tax,$args);
$termIDs = array(); //we need an array of IDs from all the terms in this taxonomy
foreach($terms as $term){
$termIDs[] = $term->term_id;
}