Skip to content

Instantly share code, notes, and snippets.

View chriswagoner's full-sized avatar

Chris Wagoner chriswagoner

  • Chicago
View GitHub Profile
@chriswagoner
chriswagoner / Get_Child_Pages.php
Created February 9, 2022 17:03
Get Child Pages
function mysite_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
@chriswagoner
chriswagoner / filterwp_sort_by_custom_field_json
Created January 26, 2022 22:20
FilterWP Sort by Custom Field (JSON)
// Here, we are getting all values so we're using a 'do not match' scenario
{
"meta_key": "field_slug",
"meta_value": 100,
"meta_type": "NUMERIC",
"meta_compare": "NOT LIKE",
"orderby": "meta_value",
"order": "DESC"
}
@chriswagoner
chriswagoner / gist:c84833d5ebec697986e15e10881e75e0
Last active January 18, 2022 16:23
Get Field and Update ACF Field on Post Save
// In this example we are getting a checkbox and dropdown field (noted below) and then calculating the sum. Then, we update a custom field with the total.
add_action( 'save_post', 'custom_field_calc', 20, 2 );
function custom_field_calc( $id, $post ) {
// bail out if this is an autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
@chriswagoner
chriswagoner / query_param_hubspot.js
Created January 14, 2022 17:00
Get Query Parameter and throw it into a form field
// Here we are targeting a Hubspot form, grabbing the GCLID (from a Google ad click) and popping it into the hidden Hubspot field value that has the ID of GCLID.
jQuery(".hs-form").submit(function() {
ga(function() {
if (jQuery('#gclid').length) {
jQuery("#gclid").val(ga.getAll()[0].get('_gclid'));
}
});
});
@chriswagoner
chriswagoner / acf_fields_from_group
Created December 29, 2021 20:56
ACF Fields from Group
// Get the Group
$thegroup = get_field('group_name');
// Get the Sub Field
echo $thegroup['sub_field_name'];
@chriswagoner
chriswagoner / acf_repeater_fields
Last active January 26, 2022 15:43
ACF_Repeater_Fields
add_shortcode( "the_shortcode", "the_function" );
function the_function() {
ob_start();
// Run the loop - Do we have a Repeater field?
if ( have_rows( 'repeater_field_name' ) ) :
echo '<div class="myclass">'; // Optional if you want to output before the fields
@chriswagoner
chriswagoner / generate-basic-fluid.css
Created December 15, 2021 14:23
GeneratePress Basic Fluid Styles
/* Base HTML */
html {
font-size: 62.5%;
}
p {
font-size: clamp(1.4rem, calc(1.4rem + ((1vw - 0.32rem) * 0.4545)), 1.8rem);
}
@chriswagoner
chriswagoner / child_page_list
Created October 5, 2021 20:12
Get the child or sibling pages
function mysite_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
@chriswagoner
chriswagoner / inject_os_browser_class.php
Created July 2, 2021 18:47
WP Inject OS Browser Class
//// Browser/OS Body Class
function mv_browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) {
@chriswagoner
chriswagoner / convert_yt_to_embed.php
Created June 2, 2021 18:54
Convert YouTube URLs to Embed URLs
function go_convert_youtube_url_to_embed_url($youtube_url) {
$matches = array();
preg_match('/((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?/', $youtube_url, $matches);
return "https://www.youtube.com/embed/".$matches[5];
}