How to display custom fields from a plugin

To retrieve a post (or product) custom field, it depends on where you want to display it. To get a single custom fields: // in your product loop, $reserved_price = get_post_meta($post->ID, ‘_auction_reserved_price’, true); echo $reserved_price; if you want to get an array of all your plugin custom fields. You must loop trough all meta for … Read more

Can’t save custom field on registration page

You need to use the show_user_profile, edit_user_profile, personal_options_update, and edit_user_profile_update hooks. You can use the following code format adding additional fields in User section. add_action( ‘show_user_profile’, ‘extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘extra_user_profile_fields’ ); function extra_user_profile_fields( $user ) { ?> <h3><?php _e(“Extra profile information”, “blank”); ?></h3> <table class=”form-table”> <tr> <th><label for=”address”><?php _e(“Address”); ?></label></th> <td> <input type=”text” name=”address” … Read more

Set checkbox as checked by default in a metabox

You are saving unchecked checkbox values as empty strings: public function save_metabox( $post_id, $post ) { // Sanitize user input. $tp_primo_new_show_below_title = isset($_POST[‘tp_primo_show_below_title’]) ? ‘checked’ : ”; … } So when you fetch the saved unchecked value and then check for if(empty(…)), it returns true and sets ‘checked’ as the default value because empty(…): Returns … Read more

Using abs() with custom field in orderby statement

Custom Class to do the custom parse class AS_Query extends \WP_Query { protected function parse_orderby($order_by) { $additional_allowed = array(); $absValue = null; if (preg_match(‘/abs\(([0-9]+)\)/i’, $order_by, $matches)) { $absValue = $matches[1]; $order_by = sprintf(‘abs((meta_value+0) – %s)’, intval($matches[1])); $additional_allowed[] = $order_by; } if (!in_array($order_by, $additional_allowed, true)) { $parent_orderby = parent::parse_orderby($order_by); if ($parent_orderby) { return $parent_orderby; } return … Read more