Skip to content

Instantly share code, notes, and snippets.

View joelstransky's full-sized avatar

Joel Stransky joelstransky

View GitHub Profile
@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 / 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');
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 (
(
<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;
@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; ?>
$the_results;
function only_run_once() {
if ( isset($the_results) ) {
return $the_results;
}
// do stuff
$the_results = $some_result_value;
return $the_results;
}
$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() ) );
}
}
<?php
$terms = get_terms( array( ‘taxonomy’ => ‘research-categories’, ‘hide_empty’ => false ) );
foreach ( $terms as $term ) {
echo $term->name;
}
?>
[{
"id": 40,
"text": "Campus Center"
}, {
"id": 35,
"text": "College of Arts &amp; Humanities"
}, {
"id": 34,
"text": "College of Education (COE)"
}, {
@joelstransky
joelstransky / acf.php
Last active July 28, 2016 21:53
acf taxonomy meta data lookup
function acf_get_terms( $args = array() ) {
global $wpdb;
$defaults = array(
'taxonomy_slug' => '',
'acf_field_name' => null,
'meta_value' => '',
);
$args = wp_parse_args( $args, $defaults );
if ( empty($args['taxonomy_slug']) || ! taxonomy_exists( $args['taxonomy_slug'] ) || empty( $args['acf_field_name'] ) ) {