Skip to content

Instantly share code, notes, and snippets.

@apatton-cnet
apatton-cnet / gist:5759832
Last active December 18, 2015 09:09
enqueue admin stylesheet on wordpress backend
<?php
function ebs_seo_cp_admin_init() {
wp_register_style('ebs_seo_cp_admin_stylesheet', plugins_url('admin-stylesheet.css', __FILE__));
}
add_action( 'admin_init', 'ebs_seo_cp_admin_init' );
function ebs_seo_cp_admin_enqueue($hook) {
$pages_array = array(
'ebs_seo_cp_menu',
'ebs_seo_cp_menu_view_options',
@apatton-cnet
apatton-cnet / gist:5832046
Created June 21, 2013 15:34
image thumbnailer
function create_image_thumbnails($image_filename) {
$image = new Imagick("images/original/" . $image_filename);
$image->scaleImage(800,0);
$image_details = $image->getImageGeometry();
if ($image_details['height'] > 600) {
$image->scaleImage(0,600);
}
$image->writeImage("images/normal/" . $image_filename);
$args = array(
'post_type' => 'post',
'post__not_in' => array($post->ID),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'post_tag',
'field' => 'id',
'terms' => (array)$tag_ids,
'operator' => 'IN'
$args = array(
'post_type' => 'my_image_post_type',
'tax_query' => array(
array(
'taxonomy' => 'body_part',
'field' => 'slug',
'terms' => 'arm'
)
)
);
$args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => $skinny
),
array(
@apatton-cnet
apatton-cnet / gist:6030344
Created July 18, 2013 15:37
add_meta_box ignoring context??? outputs box in <div id="advanced-sortables" class="meta-box-sortables ui-sortable"> rather than "normal-sortables"
<?
function ebs_seo_cp_add_custom_box_contact() {
add_meta_box(
'ebs_seo_cp_meta_box_class_contact', //id
__( 'Location Details: Contact Information', 'ebs_seo_cp' ), //title
'ebs_seo_cp_inner_custom_box_contact', //callback
'location', //post type
'normal' //context
);
}
<?php
function ebs_seo_cp_sort_columns( $vars ) {
if ( isset( $vars['post_type'] ) && 'location' == $vars['post_type'] ) {
if ( isset( $vars['orderby'] ) ) {
switch ($vars['orderby'] ) {
case 'street' :
$vars = array_merge(
<?php
add_action('post_edit_form_tag', 'ebs_seo_cp_modify_form_tag');
function ebs_seo_cp_modify_form_tag() {
echo '>';
echo '<div>Testing added content to top of page</div';
}
?>
@apatton-cnet
apatton-cnet / gist:6072705
Last active December 20, 2015 04:39
Much like Leon's additional metabox holder above the default TinyMCE editor, this will place a full width container above the text field by hacking apart the form tag via post_edit_form_tag action
<?php
add_action('post_edit_form_tag', 'ebs_seo_cp_modify_form_tag');
function ebs_seo_cp_modify_form_tag() {
$screen = get_current_screen();
if ( $screen->id != 'location') { return; } //change to custom post type
global $post;
//lets close the <form> tag
echo '>';
<?php
function my_plugin_get_custom_fields($post_id) {
$data = get_post_custom($post_id);
foreach ($data as $k => $v) {
$return[$k] = $v[0];
}
return $return;
}
$custom_fields = my_plugin_get_custom_fields($post_id);