Skip to content

Instantly share code, notes, and snippets.

View yellowberri-snippets's full-sized avatar

Dalton Yellowberri yellowberri-snippets

View GitHub Profile
@yellowberri-snippets
yellowberri-snippets / PHP: WP: WP_Query
Last active December 21, 2015 03:29
PHP: WP: WP_Query
<?php
$args = array (
'post_type' => 'post',
'posts_per_page' => -1,
'status' => 'publish'
);
$query = new WP_Query( $args );
?>
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Register Custom Post Type
Last active December 21, 2015 12:59
PHP: WP: Custom Post Type Definition
// Books Custom Post Type Definition
function books_cpt_init() {
$labels = array(
'name' => 'Books',
'singular_name' => 'Book',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'edit_item' => 'Edit Book',
'new_item' => 'New Book',
@yellowberri-snippets
yellowberri-snippets / PHP: ACF: Basic Image Field
Last active December 21, 2015 18:19
PHP: ACF: Basic Image Field
if ( get_field('image') ) {
$image = get_field('image');
// Some useful keys.
// $image['url'] - Full size image.
// $image['sizes']['medium'] - Medium size image.
// $image['alt'] - Image Alternative text field.
// $image['title'] - Image title field.
// $image['caption'] - Image caption field.
@yellowberri-snippets
yellowberri-snippets / PHP: ACF: Basic Repeater Field
Last active December 21, 2015 18:19
PHP: ACF: Basic Repeater Field
<?php
$repeaterName = 'repeater';
$pageId = NULL; // Just in case.
?>
<?php if ( have_rows( $repeaterName, $pageId ) ) : ?>
<?php while ( have_rows($repeaterName, $pageId) ) : the_row(); ?>
<?php the_sub_field('sub_field_name'); ?>
<?php endwhile; ?>
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Get All Terms in Taxonomy
Last active December 22, 2015 01:08
PHP: WP: Get All Terms in Taxonomy (even if not in post)
$taxonomy = 'services';
$terms_args = array (
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC'
);
$terms = get_terms( $taxonomy, $terms_args);
foreach ( $terms as $term ) {
echo $term->name;
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Post Expiration Query Args
Created September 4, 2013 21:00
PHP: WP: Post Expiration Query Args
// Include the ACF field "post_expiration",
// Field type = Date & Time Picker
// "Get field as timestamp" should set to "Yes".
$today = current_time('timestamp');
$args = array (
'meta_key' => 'post_expiration',
'meta_value' => $today,
'meta_compare' => '>='
@yellowberri-snippets
yellowberri-snippets / PHP: WP: Get All Users from Certain Roles
Created September 9, 2013 18:34
PHP: WP: Get All Users from Certain Roles
// Get all users from multiple roles
// http://wordpress.stackexchange.com/questions/39315/get-multiple-roles-with-get-users
function get_authors() {
$users = array();
// List these in heirarchical order
$roles = array('editor', 'author', 'contributor');
foreach ($roles as $role) :
$users_query = new WP_User_Query( array(
@yellowberri-snippets
yellowberri-snippets / SASS: Media Query Indicator
Created September 24, 2013 16:59
SASS: Media Query Indicator
#media-query {
position:fixed;
top:5px;
left:5px;
height:10px;
width:10px;
@include border-radius(100%);
z-index:999;
background-color:blue;
@yellowberri-snippets
yellowberri-snippets / JS: Class Swap Function
Created September 24, 2013 17:35
JS: Class Swap Function
function classSwap(classOne, classTwo, target) {
if ( $(target).hasClass(classOne) ) {
$(target).removeClass(classOne).addClass(classTwo);
}
else if ( $(target).hasClass(classTwo) ) {
$(target).removeClass(classTwo).addClass(classOne);
}
else {
$(target).addClass(classOne);
}
@yellowberri-snippets
yellowberri-snippets / CSS: Fix Google Map Controls Errors
Created October 24, 2013 16:36
CSS: Fix Google Map Controls Errors
img[src*="gstatic.com/"], img[src*="googleapis.com/"] {
max-width: 99999px;
}