Skip to content

Instantly share code, notes, and snippets.

/*Put this in the header*/
html{visibility: hidden;opacity:0;}
/*Put this in the footer*/
html {
visibility: visible;
opacity: 1;
}
/*
* Add post object field on the CPT you want to display
* In the post object field select the CPT post you want this post to show on
*
* Example:
* 2 CPT's - Tours and Reviews
*
* To show reviews on the relevant tours:
* - Add the post object field to the reviews CPT
* - Select the tours that I want the reviews to show on inside the Review post
//Get the Custom Post Type
// -1 means we get all the posts type.
<?php
$things = get_posts(['post_type' => 'CPT','posts_per_page' => -1]);
//Start with 0 calories
$total = 0;
//Then Loop through all the posts in your CPT
Foreach($LotsofPosts as $singlePost):
//well grab the calories from each post
<?php
//Add to Advanced Scripts
add_shortcode( 'repeater_post_class', 'lit_post_class_sc' );
/**
* Shortcode for adding post classes inside Oxygen Repeater
*/
function lit_post_class_sc( $atts, $content = null ) {
$postclasses = join( ' ', get_post_class() );
<?php
//Add dynamic class to posts
//dynamic_classes_oxygen_repeater.php
//Add this into a codeblock
<style type="text/css">
.post-<?php the_ID() ?> #DIV_ID_HERE{
background-color:<?php the_field('ACF_FIELD_HERE'); ?>;
}
<?php
/**
* Function to check if the current Page is a parent or not.
* @return bool true (1) if the current Page has children else false (0)
*/
function wpdd_is_parent_page() {
// Load details about this page.
$post = get_post();
@tdrayson
tdrayson / Relationship_field_is_not_empty.php
Last active October 28, 2020 15:45
Conditionally show a section in Oxygen based on if the CPT has posts attached to it via post object field.Links CPT's and display on frontend using post object field - https://gist.github.com/tdrayson/0b915b4d89615ca663f2bd1f03e0f364Add condition
function check_query_field( $cpt_name, $acf_field ){ //Put CPT as function name
//WP_Query arguments
$args = array(
'post_type' => array( $cpt_name ),//CPT NAME Here
'meta_query' => array(
array(
'key' => $acf_field, //ACF FIELD NAME HERE
'value' => get_the_ID(),
'compare' => 'LIKE',
@tdrayson
tdrayson / update_acf_date_field.php
Last active October 27, 2020 20:44
Update an ACF Field based on if the date is in the past.
function tct_set_new_date() {
$posts = get_posts( array('post_type' => 'session', 'posts_per_page' => - 1) );
$current_date = date( "Y-m-d h:i" );
foreach($posts as $post) {
$old_date = get_field( 'date', $post->ID );
if($old_date < $current_date) {
$new_date = date( 'Y-m-d h:i', strtotime( '+1 week', strtotime( $old_date ) ) );
update_field( 'date', $new_date, $post->ID );