Skip to content

Instantly share code, notes, and snippets.

View timmcdaniels's full-sized avatar

Tim McDaniels timmcdaniels

View GitHub Profile
/**
*Get distinct values of custom field from post type
*
*@return void
*@since 0.1
*/
function get_distinct_from_post_type ( $field, $post_type ) {
global $wpdb;
$sql = "SELECT DISTINCT meta_value FROM $wpdb->postmeta pm, $wpdb->posts p WHERE meta_key = '$field' AND pm.post_id=p.ID AND p.post_type='$post_type' ORDER BY meta_value";
return $wpdb->get_results( $sql, ARRAY_A );
@timmcdaniels
timmcdaniels / populate_acf_select_fields
Last active May 6, 2020 15:30
Populating ACF Select Fields with Post Type Values
// populate acf field (sample_field) with post types (sample_post_type)
function acf_load_sample_field( $field ) {
$field['choices'] = get_post_type_values( 'sample_post_type' );
return $field;
}
add_filter( 'acf/load_field/name=sample_field', 'acf_load_sample_field' );
function get_post_type_values( $post_type ) {
$values = array();
@timmcdaniels
timmcdaniels / get_image_src
Last active May 8, 2017 15:07
WordPress Get Image Source Function
<?php
function get_image_src( $id = 0, $size = '', $default_id = 50 ) {
$src = '';
// get src of attachment id
if ( $id > 0 ) {
list( $src, $width, $height ) = wp_get_attachment_image_src( $id, $size );
}
@timmcdaniels
timmcdaniels / wordpress_asset_enqueuing
Last active December 25, 2015 15:19
WordPress Asset Enqueing
<?php
// hook into WordPress wp_enqueue_scripts action with a high priority
// so our function is the last to run
add_action( 'wp_enqueue_scripts', 'theme_enqueue_assets', 99999 );
// function that enqueues our CSS & JavaScript
function theme_enqueue_assets() {