Skip to content

Instantly share code, notes, and snippets.

View mwangepatrick's full-sized avatar

Patrick N. Mwange mwangepatrick

View GitHub Profile
<?php if( have_rows('main_flexible_field') ): ?>
<!-- working from the main flexible content loop -->
<?php while ( have_rows('main_flexible_field') ) : the_row(); ?>
<!-- working inside the nested flex field -->
<?php while(has_sub_field("nested_flex_field")):
@mwangepatrick
mwangepatrick / child-functions.php
Created October 6, 2016 17:17 — forked from yratof/child-functions.php
Load predefined JSON files by their name, then make the list accessible to child themes
<?php
class craft_child_features {
static function setup() {
add_filter( 'craft_acf_parent_features', __CLASS__ . '::craft_child_remove_acf_groups' );
}
/**
* [craft_child_remove_acf_groups description]
* @param [type] $features [description]
<div class="my-class">
<?php
//get the shortcode value as a string.
$slider = get_field('field_name');
echo do_shortcode( $slider );
?>
</div>
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_5874cab2516b6',
'title' => 'Quiz',
'fields' => array (
array (
'layouts' => array (
array (
while ( have_posts() ) { the_post();
if( have_rows('quiz') ):
while ( have_rows('quiz') ) : the_row();
if( get_row_layout() == 'single_choice' ):
the_sub_field('question');
endif;
endwhile;
endif;
<?php
//add this piece of into your template file
global $post;
echo $post->ID;//check to verify the global post ID is correct.
//try to return the ACF value using get_field/the_field
the_field('field_name');
$value = get_field('field_name');
@mwangepatrick
mwangepatrick / add_admin_columns.php
Created March 12, 2017 13:12
Add ACF custom fields to the admin dashboard columns
<?php
/*
Plugin Name: My Salon & Spur
Description: For adding Salon and Spur managment features to a website
Author: Patrick N. Mwange
Version: 1.0.0.0
*/
function my_custom_salons() {
/* Checks to see if "is_plugin_active" function exists and if not load the php file that includes that function */
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
/* Checks to see if the acf pro plugin is activated */
if ( !is_plugin_active('advanced-custom-fields-pro/acf.php') ) {
/* load the plugin and anything else you want to do */
}
@mwangepatrick
mwangepatrick / repeater.php
Created April 15, 2017 06:30
Displaying repeater from nested repeater in the optoins page
<?php if( have_rows('add_career_opportunities', 'option') ): ?>
<div id="career-single">
<?php while( have_rows('add_career_opportunities', 'option') ): the_row();
//Variables
$title = get_sub_field('job_title');
$description = get_sub_field('job_description', 'option'); ?>
@mwangepatrick
mwangepatrick / dequeue_select_2.php
Last active November 25, 2017 08:33
ACF : Dequeue select2 Js
<?php
//here is the correct way to dequeue the select2 js used by acf
function my_acf_init() {
acf_update_setting('enqueue_select2', false); //this value defaults to true
}
add_action('acf/init', 'my_acf_init');