This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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