Skip to content

Instantly share code, notes, and snippets.

Avatar
💙
Cultivating Community @twitterdev

Tessa Kriesel tessak22

💙
Cultivating Community @twitterdev
View GitHub Profile
@tessak22
tessak22 / functions.php
Created Dec 10, 2017
Create Custom Post Type in WordPress
View functions.php
add_action('init', 'tessak22_register_custom_post_types', 0);
function tessak22_register_custom_post_types()
{
$arr_custom_post_type_options = array(
/*
array(
'label' => 'lowercase_name' // ** 20 char max, no spaces or caps
'singlar' => 'Human-Readable Item' // singular name
'plural' => 'Human-Readable Items' // plural name
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats')
@tessak22
tessak22 / upcoming-events.php
Created Dec 10, 2017
Templating for Custom Post Type sorting by ACF Date Field
View upcoming-events.php
<?php
$today = current_time('Ymd');
$args = array(
'post_type' => 'events',
'posts_per_page' => '20',
'meta_key' => 'speaking_date',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
@tessak22
tessak22 / template-file.php
Created Dec 11, 2017
Advanced Custom Fields IF Statements
View template-file.php
//Used in Template
<?php if(get_field('banner_image')): ?>
<div class="banner-image"><img class="img-responsive" src="<?php the_field('banner_image'); ?>"></div>
<?php endif; ?>
//Used in custom post types
<?php
@tessak22
tessak22 / inc-page-builder.php
Last active Oct 5, 2018
ACF Page Builder - Create file and put in template root directory
View inc-page-builder.php
<?php
// loop over the ACF flexible fields for this page / post
while ( the_flexible_field('page_builder') ) {
// load the layout from the block folder
get_template_part( 'blocks/'. get_row_layout() );
} ?>
@tessak22
tessak22 / page.php
Created Oct 5, 2018
ACF Page Builder - Add to template file
View page.php
<?php //each page builder has its own section
get_template_part('inc', 'page-builder');
?>
@tessak22
tessak22 / centered_paragraph_with_title.php
Created Oct 5, 2018
ACF Page Builder - Blocks - Centered Paragraph with Title (Create a "blocks" directory in your theme directory and place in there)
View centered_paragraph_with_title.php
<?php
$title = get_sub_field('title');
$content = get_sub_field('content');
?>
<section class="content-block centered_paragraph_with_title flex">
<div class="content col-sm-10 col-sm-offset-1 text-center">
<?php if ( $title ): ?>
<h3><?php echo $title; ?></h3>
@tessak22
tessak22 / functions.php
Created Oct 5, 2018
Dogs Custom Post Type
View functions.php
// Custom Post Types
add_action('init', 'tessak22_register_custom_post_types', 0);
function tessak22_register_custom_post_types()
{
$arr_custom_post_type_options = array(
/*
array(
'label' => 'lowercase_name' // ** 20 char max, no spaces or caps
'singlar' => 'Human-Readable Item' // singular name
'plural' => 'Human-Readable Items' // plural name
@tessak22
tessak22 / page-dogs.php
Created Oct 5, 2018
Page template to display my Dogs Custom Post Type
View page-dogs.php
<?php
/**
* Template Name: Dogs
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
@tessak22
tessak22 / functions.php
Created Oct 5, 2018
Options Page for Theme Settings with ACF
View functions.php
/**
* Add ACF Options for Theme Settings
*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
@tessak22
tessak22 / function.php
Last active Feb 21, 2019
Hero ACF Block (Requires ACF Pro 5.8)
View function.php
/**
* Register hero block
*/
add_action('acf/init', 'hero');
function hero() {
// check function exists
if( function_exists('acf_register_block') ) {
// register a hero block
You can’t perform that action at this time.