• Resolved Carin

    (@sparksfreebies)


    Hi, We need to add a Custom Field that the Admin will fill in, but it will be displayed on the Ad, we don’t want the field visible to the person filling out the Ad Form, it does not need to be searchable. Should I just try to do this with css? Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i understand you have this field created using Custom Fields extension. If so then when you edit the field (using Custom Fields editor) then in the “Display Settings” section in field “Display” you can select not to show this field in the frontend.

    Thread Starter Carin

    (@sparksfreebies)

    We do want to show it to site visitors, but it has to be filled out by our staff, so we don’t want to show it to the person creating the Ad.

    Plugin Author Greg Winiarski

    (@gwin)

    Add the code below in your theme functions.php file it will allow you to hide a field in the frontend forms

    
    add_filter( "adverts_form_load", function( $form ) {
      if( is_admin() ) {
        return $form;
      }
      if( $form["name"] != "advert" ) {
        return $form;
      }
      foreach( $form["field"] as $k => $field ) {
        if( $field["name"] == "field_to_hide_in_frontend" ) {
          unset( $form["field"][$k] );
        }
      }
      return $form;
    } );
    

    Just replace “field_to_hide_in_frontend” with actual name of the field you do not want to show in the frontend forms.

    Thread Starter Carin

    (@sparksfreebies)

    Perfect! Thank you, but I did try to add more fields, seperated by a comma
    and it did not work, do I need a separate filter for each field
    I tried this:
    if( $field["name"] == "custom_field_65,custom_field_64" )
    Thanks again!

    Plugin Author Greg Winiarski

    (@gwin)

    Please try this instead

    
    if( in_array( $field["name"], array( "custom_field_65", "custom_field_64" ) ) )
    
    Thread Starter Carin

    (@sparksfreebies)

    Hooray, thank you!

    Thread Starter Carin

    (@sparksfreebies)

    (I am using the Custom Fields addon) The new Custom Fields are showing to Admin, but not in Display Ad page, I believe we are using single.php for Display Ad page, because I do not have single-advert.php in the templates’ folder, but information is not transferring from the form to the Listing. I removed the code above just to see if that was having an effect, and its not, I still can’t see the new custom fields.https://tbreds.net/advert/successful-slew-19/ https://www.screencast.com/t/fBWdFpbJXxsU

    Plugin Author Greg Winiarski

    (@gwin)

    Using the Custom Fields extension is this field configured to show “anywhere” and does the Ad you linked to have a value for this field filled?

    Thread Starter Carin

    (@sparksfreebies)

    Yes, Display is set to Forms and Ad Display, and since I removed the code you helped me with to hide the fields in Forms, it is now showing in Listing Form, https://www.screencast.com/t/7OHiIVdZde but when we entered the data from the backend, it did not show up in Ad Listing (this listing had the data entered from backend, but does not display in Ad Listing, https://tbreds.net/advert/successful-slew-19/

    Plugin Author Greg Winiarski

    (@gwin)

    I am not sure then, you seem to have it configured correctly, maybe there were some changes to the wpadverts/templates/single.php (or you are using a custom one) which does not have the “adverts_tpl_single_details” action responsible for displaying custom fields data?

    Thread Starter Carin

    (@sparksfreebies)

    Its been a while since this was setup, how would I tell if I have a custom template, (this is my template folder list, https://www.screencast.com/t/wfiODbfBg) this is my single.php

     <?php
    
        wp_enqueue_style( 'adverts-frontend' );
    
        wp_enqueue_style( 'adverts-icons' );
    
        wp_enqueue_style( 'adverts-icons-animate' );
    
        wp_enqueue_script( 'adverts-frontend' );
    
    ?>
    
    <?php do_action( "adverts_tpl_single_top", $post_id ) ?>
    
    <div class="adverts-single-box">
    
        <div class="adverts-single-author">
    
            <div class="adverts-single-author-avatar">
    
                <?php $id_or_email = get_post_field( 'post_author', $post_id ) ?>
    
                <?php $id_or_email = $id_or_email ? $id_or_email : get_post_meta($post_id, 'adverts_email', true) ?>
    
                <?php echo get_avatar( $id_or_email, 48 ) ?>
    
            </div>
    
            <div class="adverts-single-author-name">
    
                <?php echo apply_filters( "adverts_tpl_single_posted_by", sprintf( __("by <strong>%s</strong>", "wpadverts"), get_post_meta($post_id, 'adverts_person', true) ), $post_id ) ?><br/>
    
                <?php printf( __('Published: %1$s (%2$s ago)', "wpadverts"), date_i18n( get_option( 'date_format' ), get_post_time( 'U', false, $post_id ) ), human_time_diff( get_post_time( 'U', false, $post_id ), current_time('timestamp') ) ) ?>
    
            </div>
    
        </div>
    
      
        <?php if( get_post_meta( $post_id, "adverts_price", true) ): ?>
    
        <div class="adverts-single-price">
    
            <span class="adverts-price-box"><?php echo esc_html( adverts_get_the_price( $post_id ) ) ?></span>
    
        </div>
    
        <?php elseif( adverts_config( 'empty_price' ) ): ?>
    
        <div class="adverts-single-price adverts-price-empty">
    
            <span class="adverts-price-box"><?php echo esc_html( adverts_empty_price( get_the_ID() ) ) ?></span>
    
        </div>
    
        <?php endif; ?>
    
    </div>
    
    <div class="adverts-grid adverts-grid-closed-top adverts-grid-with-icons adverts-single-grid-details">
    
        <?php $advert_category = get_the_terms( $post_id, 'advert_category' ) ?>
    
        <?php if(!empty($advert_category)): ?> 
    
        <div class="adverts-grid-row ">
    
            <div class="adverts-grid-col adverts-col-30">
    
                <span class="adverts-round-icon adverts-icon-tags"></span>
    
                <span class="adverts-row-title"><?php _e("Category", "wpadverts") ?></span>
    
            </div>
    
            <div class="adverts-grid-col adverts-col-65">
    
                <?php foreach($advert_category as $c): ?> 
    
                <a href="<?php echo esc_attr( get_term_link( $c ) ) ?>"><?php echo join( " / ", advert_category_path( $c ) ) ?></a><br/>
    
                <?php endforeach; ?>
    
            </div>
    
        </div>        
    
        <?php endif; ?>
    
            
        <?php if(get_post_meta( $post_id, "adverts_location", true )): ?>
    
        <div class="adverts-grid-row">
    
            <div class="adverts-grid-col adverts-col-30">
    
                <span class="adverts-round-icon adverts-icon-location"></span>
    
                <span class="adverts-row-title"><?php _e("Location", "wpadverts") ?></span>
    
            </div>
    
            <div class="adverts-grid-col adverts-col-65">
    
                <?php echo apply_filters( "adverts_tpl_single_location", esc_html( get_post_meta( $post_id, "adverts_location", true ) ), $post_id ) ?>
    
            </div>
    
        </div>
    
        <?php endif; ?>
    
       
        <?php do_action( "adverts_tpl_single_details", $post_id ) ?>
    
    </div>
    
    <div class="adverts-content">
    
        <?php echo $post_content ?>
    
    </div>
    
    <?php do_action( "adverts_tpl_single_bottom", $post_id ) ?>
    Thread Starter Carin

    (@sparksfreebies)

    We found it, there was a custom plugin controlling the final display, thanks for your assistance!!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Display Custom Field in Ad but not in Form for User’ is closed to new replies.