Skip to content

Instantly share code, notes, and snippets.

@DanielFloeter
Last active September 5, 2022 18:57
Show Gist options
  • Save DanielFloeter/c3044851cc3d69341a536b3e18e08d5a to your computer and use it in GitHub Desktop.
Save DanielFloeter/c3044851cc3d69341a536b3e18e08d5a to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Custom-placeholder Add-on (ACF)
Plugin URI: http://tiptoppress.com/downloads/term-and-category-based-posts-widget/
Description: Add-on to handle custom placeholder like custom fields for the premium widget Term and Category Based Posts Widget.
Author: TipTopPress
Version: 1.1
Author URI: http://tiptoppress.com
Installation:
- Download the file and rename it to Custom-placeholder-Add-on.php
- Upload it to the plugins folder [your-wordpress-installation]/wp-content/plugins/Custom-placeholder-Add-on.php
- Go to WordPress > Admin > PlugIns and activate the Extension
- Now, there is a new sort by: 'Name' visible
*/
namespace termCategoryPostsPro\CustomPlaceholderAddOn;
// Don't call the file directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Applied to the list of sort orders some new ones.
*
* @return array of sort orders
*
* @since 1.1
*/
function custom_field ( $custom_field_name, $that, $instance ) {
// if values with get_field() or
// else if taxonomy objects with get_field_object()
if ( function_exists( 'get_field' ) ) {
$custom_field_value = get_field( $custom_field_name );
// uncomment for debug output to /wp-content/debug.log and set define( 'WP_DEBUG, true' ) in your wp-config.php
// error_log("Filter debug cpwp_custom_placeholder: " . var_dump( $custom_field_name ));
if ( ! empty( $custom_field_value ) ) {
if ( $custom_field_name == 'my_custom_field' ) { // replace 'my_custom_field' with your custom field name
return "Title: " . $custom_field_value->name . "</br>";
} else if ( $custom_field_name == 'my_second_custom_field' ) { // replace 'my_custom_field' with your custom field name
return "Office Location: " . $custom_field_value->location . "</br>";
} else if ( $custom_field_name == 'my_array' ) { // replace 'my_custom_field' with your custom field name if it's an arry
$values = "";
if ( $custom_field_value ) {
foreach ( $custom_field_value as $value) {
$values .= '<span>' . $value . '</span>';
}
}
return $values;
}
}
}
}
add_filter( 'cpwp_custom_placeholder', __NAMESPACE__.'\custom_field', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment