Skip to content

Instantly share code, notes, and snippets.

View sinisteralex's full-sized avatar
☠️
I may be slow to respond.

sinisteralex

☠️
I may be slow to respond.
View GitHub Profile
@jpcontrerasv
jpcontrerasv / ACF If Else field.php
Created August 26, 2016 04:46
ACF If Else field
<?php if ( get_field( 'field_name' ) ): ?>
This is displayed when the field_name is TRUE or has a value.
<?php else: // field_name returned false ?>
This is displayed when the field is FALSE, NULL or the field does not exist.
<?php endif; // end of if field_name logic ?>
@MelMacaluso
MelMacaluso / expose_ACF_fields_to_REST.php
Created June 4, 2019 22:54
Automatically expose all the ACF fields to the Wordpress REST API in Pages and in your custom post types.
<?php
function create_ACF_meta_in_REST() {
$postypes_to_exclude = ['acf-field-group','acf-field'];
$extra_postypes_to_include = ["page"];
$post_types = array_diff(get_post_types(["_builtin" => false], 'names'),$postypes_to_exclude);
array_push($post_types, $extra_postypes_to_include);
foreach ($post_types as $post_type) {
register_rest_field( $post_type, 'ACF', [
@ajskelton
ajskelton / wp-external-image-handler.php
Last active March 15, 2022 04:47
WordPress External Image Handler - Add External URL image as featured image for a post
/**
* Uploads an image from remote url and sets as featured image of the new post
*
* @param int $post_id The id of the new post
* @param string $thumbnail_url Url of the preview image hosted by BrightTalk
*/
private function image_handler( $post_id, $thumbnail_url ) {
$image_url = $thumbnail_url; // Define the image URL here
$image_name = basename( $thumbnail_url );