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

Get Post Terms of Current Post (selected taxonomy term) – How to get only the taxonomy value and not “Array ( [0] => taxonomy term )” in the frontend?

Assuming the taxonomy name is “animals” <?php //This will show all the terms in taxonomy whether they have posts or not thus the “hide_empty” $terms = get_terms( array ( ‘taxonomy’ => ‘animals’, ‘hide_empty’ => false, ‘parent’ => 0, ‘orderby’ => ‘description’, ‘order’ => ‘ASC’ )); foreach ($terms as $term) { // The $term is an … 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

How to get a custom type post data when it has a connection with another custom type post?

If in a country looking for cities $args = array ( ‘post_type’ => ‘cities’, ‘meta_key’ => ‘country’, ‘meta_value’ => get_the_ID() ); This assumes that the “Country > Name* > [drop down]” you screenshot saves that the selected value using post_meta and is saving the country’s post ID. (If it does not please adjust or specify). … 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