Skip to content

Instantly share code, notes, and snippets.

View badcrocodile's full-sized avatar

Jason badcrocodile

  • The Motley Fool
  • Austin, Texas
View GitHub Profile
Testing CLI uplaods to Github
@badcrocodile
badcrocodile / print_custom_fields.php
Created July 11, 2013 01:22
Dumps all custom fields attached to given page ID.
<?php
$custom_fields = get_post_custom(985);
// Prints out all custom field names and values
echo "<p style='line-height:2em;'>";
/*
* We only want our special ACF's,
* so lets set up a string comparison
*/
$findMe = 'gcfx_'; // Notice the naming convention!! All fields you want to use here need this. Should make it into a variable.
@badcrocodile
badcrocodile / print_named_custom_field.php
Last active December 19, 2015 14:49
Prints a custom field value by name.
<?php
// Prints the custom field of your choice
$my_custom_field = $custom_fields['gcfx_art_category_field_id'];
foreach ( $my_custom_field as $key => $value )
echo $key . " => " . $value . "<br />";
?>
<?php
// To wrap it up, lets add our custom field values to the body content of the post so Wordpress search can pick them up (it doesn't include custom fields in search).
$new_content = "<h1>$post->post_title</h1>";
$new_content .= "<div id=\"expertise_in\">";
$new_content .= "<div class=\"category_list\"><h2>Expertise:</h2>";
$new_content .= $return;
$new_content .= "</div>";
$new_content .= "<div class=\"tag_list\"><h3>Other topics listed:</h3>";
$new_content .= $misc_topics;
$new_content .= "</div>";
jQuery(document).ready(function($) {
$('.droplink').click(function() {
$(this).children().slideToggle();
});
});
@badcrocodile
badcrocodile / gist:8865833
Last active August 29, 2015 13:56
Create new wp_query via shortcode (paginated and non paginated)
<?php
/*
Plugin Name: Custom WP_Query shortcode
Plugin URI: http://goshen.edu/tuts/plugins/custom-wp_query-shortcode/
Description: Adds shortcodes to create custom loops inside posts or pages. Read <a href="http://www.goshen.edu/tuts/plugins/custom-wp_query-shortcode/">usage instructions</a> for more details.
Author: Jason Pollock
Version: 1.1
Author URI: http://goshen.edu/com-mar/meet-the-staff/
*/
function custom_query_shortcode($atts) {
<?php $image_id = get_post_thumbnail_id(); ?>
<?php $image_url = wp_get_attachment_image_src($image_id, 'medium', true); ?>
<?php $img = wp_get_image_editor($image_url[0]); ?>
<?php
if ( ! is_wp_error( $img ) ) {
$img->resize( 100, 123, true );
}
?>
<h3>HERE: </h3>
<pre>
@badcrocodile
badcrocodile / GA-friendly-facebook-share-button.php
Last active August 29, 2015 14:03
A facebook share button that supports custom GA event tracking.
<!-- https://developers.facebook.com/docs/sharing/reference/share-dialog -->
<div id="shareButton" data-href="<?php echo $bar_fb_url_conf; ?>" style="outline:1px solid red; width: 86px; height:20px; position: relative;"></div>
<script>
$('#shareButton').click(function() {
FB.ui({
method: 'share',
href: $(this).data('href'),
}, function(response){
@badcrocodile
badcrocodile / map-checkboxes.js
Created August 6, 2014 14:23
map a group of checkboxes into an array in three lines of jquery
// Find all of the checked boxes in the container and map them into an array
var searchIDs = $checkboxContainer.find('input:checkbox:checked').map(function() {
return $(this).val();
}).get();
// searchIDs is now an array containing the values of the checked boxes.
@badcrocodile
badcrocodile / index.html
Last active August 29, 2015 14:05 — forked from anonymous/index.html
Center text vertically
<div>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
</div>