Skip to content

Instantly share code, notes, and snippets.

View ashleycam3ron's full-sized avatar

Ashley N Cameron ashleycam3ron

View GitHub Profile
@ashleycam3ron
ashleycam3ron / firmware-archive.php
Last active March 4, 2020 19:08
Need to check if a user is logged in, then whether their products (in an ACF repeater) are in the loop of firmware posts (on this archive). The firmware CPT has an ACF relationship field to its products.
<?php if ( is_user_logged_in() ) { ?>
<h1>Firmware Updates</h1>
<?php $current_user = wp_get_current_user(); ?>
<h3 style="margin-bottom: 6px;">Welcome, <?php echo $current_user->user_firstname; ?>!</h3>
<p>Your registered product software and updates are listed below.<br/>
Need to register another product on your account? Please fill out a <a data-fancybox href="#updateaccount">request form</a>.</p>
<?php // Software notes
@ashleycam3ron
ashleycam3ron / software-notes
Last active March 3, 2020 00:31
Get software notes for firmware updates equal to user's products
<?php // Software notes
if( have_rows('products', $userID) ): ?>
<?php while( have_rows('products', $userID) ): the_row();
$product = get_sub_field('product'); //get repeater post object
if ($product):
//print_r($product);
@ashleycam3ron
ashleycam3ron / Excel VBA Script
Last active April 5, 2021 15:56
Excel vlookup to return multiple values as comma separated list in one cell
Option Explicit
Function LookupCSVResults(lookupValue As Variant, lookupRange As Range, resultsRange As Range) As String
Dim s As String 'Results placeholder
Dim sTmp As String 'Cell value placeholder
Dim r As Long 'Row
Dim c As Long 'Column
Const strDelimiter = "|||" 'Makes InStr more robust
s = strDelimiter
@ashleycam3ron
ashleycam3ron / add_title_and_alt_to_post_thumbnail.php
Created February 17, 2020 22:13
Add Title and Alt Attribute to WordPress Image the_post_thumbnail
<?php /* Add Title and Alt Attribute to WordPress Image the_post_thumbnail */
function ac_add_img_title( $attr, $attachment = null ) {
$img_title = trim( strip_tags( $attachment->post_title ) );
// or get the title instead of image title $attr['title'] = the_title_attribute( 'echo=0' );
$attr['title'] = $img_title;
$attr['alt'] = $img_title;
return $attr;
}
@ashleycam3ron
ashleycam3ron / gist:983db3d607abd9a1692020391a1d1a73
Last active July 4, 2018 15:19
Loop through CPT and Display Taxonomy Terms as heading if posts exist and CPT posts within
<?php
$tax_args = array(
'orderby' => 'title',
'order' => 'ASC',
'hide_empty' => true,
);
$terms = get_terms('vendors', $tax_args);
foreach($terms as $term){
<?php /* Loop through Promotion and Display Vendors as heading and promo posts within */
$post_type = 'promotion';
// Get all the taxonomies for this post type
$object = 'post';
$output = 'objects';
$taxonomies = get_object_taxonomies( $object, $output );
$exclude = array( 'post_tag','post_format','category' );
foreach( $taxonomies as $taxonomy ) :
@ashleycam3ron
ashleycam3ron / functions.php
Created February 18, 2018 16:24
Add WordPress Jetpack Publicize to Custom Post Types
$args = array(
'supports' => array( 'title', 'editor', 'thumbnail', 'publicize')
)
@ashleycam3ron
ashleycam3ron / functions.php
Created February 2, 2018 19:39
Register and Enqueue Font Awesome in WordPress
<?php
add_action('wp_enqueue_scripts', 'enqueue');
function enqueue(){
//Font Awesome
wp_register_script('font-awesome', '//use.fontawesome.com/releases/v5.0.6/js/all.js');
//enqueue scripts
wp_enqueue_script(array('jquery','font-awesome'));
@ashleycam3ron
ashleycam3ron / check-nth-post.php
Created January 13, 2018 17:01 — forked from bryceadams/check-nth-post.php
check every nth post wordpress
<?php
// $the_query would just be a standard WP_Query
if ( $the_query->have_posts() ) :
$counter = 1;
while ( $the_query->have_posts() ) : $the_query->the_post();
if ( $counter % columns == 1 ) {
// do something at the start of your 'row'
@ashleycam3ron
ashleycam3ron / wp_custom_loop_with_pagination
Created January 13, 2018 17:00
WordPress custom loop with pagination
<?php
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
$paged = get_query_var('page');
} else {
$paged = 1;
}
$custom_query_args = array(