Skip to content

Instantly share code, notes, and snippets.

View joelstransky's full-sized avatar

Joel Stransky joelstransky

View GitHub Profile
<?php
$terms = get_terms( array( ‘taxonomy’ => ‘research-categories’, ‘hide_empty’ => false ) );
foreach ( $terms as $term ) {
echo $term->name;
}
?>
$post_id = (int) $_POST['post_id'];
$query = new WP_Query( array( 'p' => $post_id ) );
if( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
write_log( array( 'is post' , get_post_format() ) );
}
}
$the_results;
function only_run_once() {
if ( isset($the_results) ) {
return $the_results;
}
// do stuff
$the_results = $some_result_value;
return $the_results;
}
@joelstransky
joelstransky / My_Page_Template.php
Last active September 2, 2016 02:14
PHP: scope of global keyword
<?php
/**
* Template Name: My Page Template
*/
?>
<?php // the_post() already uses `global $post;`, so why is it needed again on line 11 in content-my_page.php? ?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/page', 'header'); ?>
<?php get_template_part('templates/content', 'my_page'); ?>
<?php endwhile; ?>
<div class="content-main">
<?php
// check if the flexible content field has rows of data
if( have_rows('flexible_blocks') ):
// loop through the rows of data
while ( have_rows('flexible_blocks') ) : $row = the_row();
switch (get_row_layout()) {
case 'inserted_content':
global $post;
USE development;
SELECT wp_posts.ID FROM wp_posts
INNER JOIN
wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
INNER JOIN
wp_term_taxonomy ON (wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id)
INNER JOIN
wp_terms ON (wp_terms.term_id = wp_term_taxonomy.term_id)
WHERE 1=1 AND (
(
@joelstransky
joelstransky / hide_yoast_seo_meta_box.php
Last active November 8, 2016 01:41
Hide Yoast SEO meta boxes
<?php
// hide Yoast SEO from non-admin
function hide_yoastseo() {
if ( !current_user_can( 'administrator' ) ) :
remove_action('admin_bar_menu', 'wpseo_admin_bar_menu',95);
remove_menu_page('wpseo_dashboard');
endif;
}
add_action( 'admin_init', 'hide_yoastseo');
@joelstransky
joelstransky / step_1.php
Last active December 8, 2016 21:23
Inject non-acf fields during the rendering of acf-form
<?php
add_filter('acf/prepare_field', 'acf_prepare_field__inject_form_fields');
function acf_prepare_field__inject_form_fields( $field ) {
if ( ! is_admin() ) {
// look for the field AFTER where we want to inject something
// I used a switch to make it easier to react to multiple insertion points
switch ($field['key']) {
case 'field_123a456b78c90':
acf_form_inject__excerpt();
break;
@joelstransky
joelstransky / get_field_object.php
Last active December 8, 2016 21:55
Display a single ACF field form view
<?php $field = get_field_object('field_123a456b78c90'); ?>
@joelstransky
joelstransky / bootstrap3-fixed-width-columns-mixins.scss
Created December 14, 2016 23:52
Bootstrap3 Fixed Width Columns mixin
// demo: http://codepen.io/JoelStransky/pen/VKPVAG
// breakpoint list ('column type', 'screen breakpoint', 'container width @ break point')
$breakpoints: ( ('xs', $screen-xs, $screen-xs), ('sm', $screen-sm, $container-sm), ('md', $screen-md, $container-md), ('lg', $screen-lg, $container-lg) );
@mixin make-fixed-grid() {
@each $item in $breakpoints {
@media (min-width: #{nth($item, 2)} ) {
// background: red;
@include make-fixed-grid-columns( $grid-columns, nth($item, 1), width, nth($item, 3) );
}