Skip to content

Instantly share code, notes, and snippets.

@caratage
caratage / query.php
Created November 27, 2012 04:19
query_posts exclude by meta key
// Set up a custom query
$featured_query = new WP_query();
// Your query args
$featured_args=array(
'post_type'=>'post',
'meta_key'=>'featured_product',
'meta_value'=>'1'
);
@caratage
caratage / custom-js.js
Created November 24, 2012 06:49
Reusable Custom Meta Boxes JavaScript
jQuery(function(jQuery) {
jQuery('#media-items').bind('DOMNodeInserted',function(){
jQuery('input[value="Insert into Post"]').each(function(){
jQuery(this).attr('value','Use This Image');
});
});
jQuery('.custom_upload_image_button').click(function() {
@caratage
caratage / add_meta_box.php
Created November 24, 2012 06:48
Reusable Custom Meta Boxes
<?
/**
* Reusable Custom Meta Boxes by Tammy Hart
*
*
*/
// Add the Meta Box
function add_custom_meta_box() {
add_meta_box(
'custom_meta_box', // $id
@caratage
caratage / functions.php
Created November 23, 2012 19:37
Dropdown menus to sort by custom taxonomies
function taxonomy_filter_restrict_manage_posts() {
global $typenow;
// If you only want this to work for your specific post type,
// check for that $type here and then return.
// This function, if unmodified, will add the dropdown for each
// post type / taxonomy combination.
$post_types = get_post_types( array( '_builtin' => false ) );
@caratage
caratage / functions.php
Created November 23, 2012 19:31
Edit custom post columns
add_filter("manage_edit-artist_columns", "artist_edit_columns");
function artist_edit_columns($columns) {
$columns = array(
'cb' => '<input type="checkbox"/>',
'thumbnail' => __('Image'),
'title' => __('Artist'),
'performance' => __('Type'),
'slides_home' => __('on Homepage'),
);
@caratage
caratage / functions.php
Created November 23, 2012 19:28
Manage custom posts columns, show custom taxonomies
add_action("manage_posts_custom_column", "artist_custom_columns");
function artist_custom_columns($column) {
global $post;
switch ($column) {
case "performance":
$_taxonomy = 'artist_performance';
$terms = get_the_terms( $post_id, $_taxonomy );
if ( !empty( $terms ) ) {
@caratage
caratage / functions.php
Created November 23, 2012 19:26
Order custom post type columns in admin on load
function set_artist_post_types_admin_order($wp_query) {
if (is_admin()) {
// Get the post type from the query
$post_type = $wp_query->query['post_type'];
if ( $post_type == 'artist') {
// check if parameter is not set yet
@caratage
caratage / function.php
Created November 23, 2012 18:39
Add image sizes for thumbnails
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'unlimited-width-thumb', 9999, 200 ); // unlimited width, 200 pixels height
add_image_size( 'cropped-thumb', 200, 100, true ); // (cropped)
}
@caratage
caratage / functions.php
Created November 23, 2012 18:35
Use hidden custom fields with Codepress Admin Columns (cpac)
add_filter('cpac_use_hidden_custom_fields', '__return_true'); /* enables the use hidden custom fields */
@caratage
caratage / functions.php
Created November 23, 2012 18:27
Set WordPress thumbnail quality to 100%
/**
* jpeg_quality_callback
*
* set thumbnail quality to 100%
*/
function jpeg_quality_callback($arg) {
return (int)100;
}