Skip to content

Instantly share code, notes, and snippets.

function my_acf_shortcode( $atts ){
$atts = shortcode_atts( array(
'field' => '',
'image' => ''
), $atts, 'showfield' );
if ( get_field( $atts['field'] ) && ( $atts['image'] !== '' ) ) :
return '<a href="' . get_field( $atts['field'] ) . '"><img src="' . $atts['image'] . '"></a>';
endif;
}
function list_child_pages() {
global $post;
if ( is_page() && $post->post_parent )
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
else
$childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
if ( $childpages ) {
$string = '<ul>' . $childpages . '</ul>';
<div <?php post_class( get_the_ID() == get_queried_object_id() ? 'oxy-post current-post' : 'oxy-post'); ?>>
<a class='oxy-post-title' href='<?php the_permalink(); ?>'><?php the_title(); ?></a>
</div>
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/**
* Change the length of excerpt.
*
* @param int $length The number of words. Default 55.
* @return int New excerpt length.
*/
function custom_excerpt_length( $length ) {
return 20; // number of words. Default is 55.
<?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 / Conditionally_display CPT_based_on_post_object_field.php
Last active November 8, 2020 11:43
If you trying to query the post object field to between 2 CPT's. This condition checks if the repeater is empty or not.
// Add the function to advanced scripts (or code snippet)
// Create a condition in the builder to the section where you want to hide
// Select dynamic data -> php function -> “Check_CPT_Repeater”
// Inside the arguments section add your "cpt_name" and post object "acf_field"
// Set dynamic data == 0 (to hide if no results are returned)
function Check_CPT_Repeater( $cpt_name, $acf_field ){
//WP_Query arguments
$args = array(
//PHP Custom Code - plugins loaded
if ( function_exists( 'acf_add_options_page' ) ) {
acf_add_options_page();
}
function tct_field($field_name) {
return get_field( $field_name, 'option' );
}
/*Put this in the header*/
html{visibility: hidden;opacity:0;}
/*Put this in the footer*/
html {
visibility: visible;
opacity: 1;
}
//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