Title: hide custom field
Last modified: August 21, 2016

---

# hide custom field

 *  [duttasanjib2003](https://wordpress.org/support/users/duttasanjib2003/)
 * (@duttasanjib2003)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/)
 * In my wordpress theme i am creat some custom fields like “cp_street, cp_city,
   cp_mobile_no, cp_company_name” in post details ‘cp_get_ad_details( $post->ID,
   $cat_id ); ‘all fields display serialy, but i want to like address (cp_street,
   cp_city) top of page and mobile no.( cp_mobile_no) right side of page and other
   display same place. Please help me…

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741391)
 * You can use the more generic `get_post_meta()` to return the custom field values,
   which can then be assigned to variables. You can then echo out the variables 
   where ever you like.
 *  Thread Starter [duttasanjib2003](https://wordpress.org/support/users/duttasanjib2003/)
 * (@duttasanjib2003)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741397)
 * Thanks for replay.
    i am don’t understand php in depth so please describe me 
   details in code..
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741464)
 * Sorry, I can’t in specific code. I’ve no idea what `cp_get_ad_details()` specifically
   does. Like how are the custom fields stored? In a single array? Associative or
   indexed array? As individual values? What is the postmeta key or keys used to
   store the data? Or the keys for associative arrays?
 * Let’s say the data is stored in individual fields and you want to display the
   post’s associated mobile number on a particular template. I’ll assume the postmeta
   key is ‘cp_mobile_no’ for this example. You would place the following code on
   the template file, somewhere inside the “Loop”. You would need to be attentive
   to if the code is placed amongst HTML or inside of an existing `<?php ?>` block.
   This code is for amongst HTML. If inside a `<?php ?>` block, drop the additional`
   <?php ?>` code, because you cannot nest `<?php ?>` blocks. This is the code:
   `
   <?php echo get_post_meta( get_the_ID(), 'cp_mobile_no', true); ?>`
 * I did not assign to a variable in this example, that approach is more applicable
   to where all the data is stored in an array.
 *  Thread Starter [duttasanjib2003](https://wordpress.org/support/users/duttasanjib2003/)
 * (@duttasanjib2003)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741472)
 * Thanks for replay.
    I want to just hide this field which is print on my ad details
   page (all fields display serialy) not delete because mobile no. displayed in 
   other place in same page. please see this page [http://www.opendeals.in/ads/accountant-job-2/](http://www.opendeals.in/ads/accountant-job-2/)
 * Code Details
    ————- single-ad_listing.php
 * <?php // 3.0+ display the custom fields instead (but not text areas) cp_get_ad_details(
   $post->ID, $cat_id ); ?>
 * Theme-functions.php
 * // display all the custom fields on the single ad page, by default they are placed
   in the list area
    if ( ! function_exists(‘cp_get_ad_details’) ) { function cp_get_ad_details(
   $post_id, $category_id, $location = ‘list’ ) { global $wpdb;
 *  // see if there’s a custom form first based on category id.
    $form_id = cp_get_form_id(
   $category_id );
 *  $post = get_post( $post_id );
    if ( ! $post ) return;
 *  // if there’s no form id it must mean the default form is being used
    if ( !
   $form_id ) {
 *  // get all the custom field labels so we can match the field_name up against
   the post_meta keys
    $sql = “SELECT field_label, field_name, field_type FROM $
   wpdb->cp_ad_fields”;
 *  } else {
 *  // now we should have the formid so show the form layout based on the category
   selected
    $sql = $wpdb->prepare( “SELECT f.field_label, f.field_name, f.field_type,
   m.field_pos FROM $wpdb->cp_ad_fields f “ . “INNER JOIN $wpdb->cp_ad_meta m ON
   f.field_id = m.field_id WHERE m.form_id = %s ORDER BY m.field_pos ASC”, $form_id);
 *  }
 *  $results = $wpdb->get_results( $sql );
 *  if ( ! $results ) {
    _e( ‘No ad details found.’, APP_TD ); return; }
 *  // allows to hook before ad details
    cp_action_before_ad_details( $results, 
   $post, $location );
 *  foreach ( $results as $result ) {
 *  // external plugins can modify or disable field
    $result = apply_filters( ‘cp_ad_details_field’,
   $result, $post, $location ); if ( ! $result ) continue;
 *  $disallow_fields = array( ‘cp_price’, ‘cp_currency’ );
    if ( in_array( $result-
   >field_name, $disallow_fields ) ) continue;
 *  $post_meta_val = get_post_meta( $post->ID, $result->field_name, true );
    if (
   empty( $post_meta_val ) ) continue;
 *  if ( $location == ‘list’ ) {
    if ( $result->field_type == ‘text area’ ) continue;
 *  if ( $result->field_type == ‘checkbox’ ) {
    $post_meta_val = get_post_meta( 
   $post->ID, $result->field_name, false ); $post_meta_val = implode( “, “, $post_meta_val);}
 *  $args = array( ‘value’ => $post_meta_val, ‘label’ => $result->field_label, ‘
   id’ => $result->field_name, ‘class’ => ” );
    $args = apply_filters( ‘cp_ad_details_’.
   $result->field_name, $args, $result, $post, $location );
 *  if ( $args )
    echo ‘<li id=”‘ . $args[‘id’] . ‘” class=”‘ . $args[‘class’] .‘”
   ><span>’ . esc_html( translate( $args[‘label’], APP_TD ) ) . ‘:</span> ‘ . appthemes_make_clickable(
   $args[‘value’] ) . ”;
 *  } elseif ( $location == ‘content’ ) {
    if ( $result->field_type != ‘text area’)
   continue;
 *  $args = array( ‘value’ => $post_meta_val, ‘label’ => $result->field_label, ‘
   id’ => $result->field_name, ‘class’ => ‘custom-text-area dotted’ );
    $args = 
   apply_filters( ‘cp_ad_details_’ . $result->field_name, $args, $result, $post,
   $location );
 *  if ( $args )
    echo ‘<div id=”‘ . $args[‘id’] . ‘” class=”‘ . $args[‘class’] .‘”
   ><h3>’ . esc_html( translate( $args[‘label’], APP_TD ) ) . ‘</h3> ‘ . appthemes_make_clickable(
   $args[‘value’] ) . ‘</div>’;
 *  }
    }
 *  // allows to hook after ad details
    cp_action_after_ad_details( $results, $post,
   $location ); } }
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741503)
 * Ah, I think I understand now. Sorry for my confusion.
 * To simply hide the mobile entry as an example, place the following CSS code on
   your theme’s (better yet, child theme’s) style.css file:
 *     ```
       #cp_mobile_no {
           display: none;
       }
       ```
   
 * Every field in the list has an ID similar to “cp_mobile_no”. You can see the 
   IDs when you view the page in source view if you’re not sure of the ID. Use the
   same CSS as the example for any field you wish to hide, adjusting the ID to match
   the field being hidden.
 *  Thread Starter [duttasanjib2003](https://wordpress.org/support/users/duttasanjib2003/)
 * (@duttasanjib2003)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741508)
 * Thank you my problem is solved, thanks again…

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘hide custom field’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 6 replies
 * 2 participants
 * Last reply from: [duttasanjib2003](https://wordpress.org/support/users/duttasanjib2003/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/hide-custom-field/#post-4741508)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
