Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • This is my solution for anyone else wanting to use Bootstrap 3 Accordion in WordPress:

    ACF Field = “faqs”
    Repeater Sub Fields = “question”, “answer”

    
    <?php
    $counter = 1;
    if( have_rows('faqs') ):
    
     echo "<div class='panel-group' id='accordion'>";
        while ( have_rows('faqs') ) : the_row();
    
    $count = $counter++;
    
        echo "<div class='panel panel-default'>
        <div class='panel-heading'>
          <h4 class='panel-title'>
            <a data-toggle='collapse' data-parent='#accordion' href='#collapse" . $count . "'>";
            the_sub_field('question');
        echo "</a>
          </h4>
        </div>
        <div id='collapse" . $count . "' class='panel-collapse collapse'>
          <div class='panel-body'>";
          the_sub_field('answer');
        echo "</div>
        </div>
      </div>";
    
        endwhile;
    
        echo "</div>";
    else :
    endif;
    ?>
    

    Note: I’ve removed the “in” from the answer class so all panels will be closed on page load. If you want all to be open then use this instead:

    class=’panel-collapse collapse in’

  • I have done this using this add on https://wordpress.org/plugins/acf-enhanced-message-field/

    I have added “buttons” that fire ajax requests and other things. It has not been updated in a while and I’m getting a little worried about it.

  • So, your question caused me to look into this some more, since the discussion you linked to is 2 years old. What I found is that ACF is showing options pages and adding custom fields to options pages in a completely different way that it use to.

    Now:

    ACF adds field groups to options pages using add_meta_box() https://developer.wordpress.org/reference/functions/add_meta_box/

    ACF shows field groups by calling do_meta_boxes() https://developer.wordpress.org/reference/functions/do_meta_boxes/

    There is also a hook in ACF named “acf/input/admin_head” and we can use this hook with a priority of <10 or >10 to add our own custom metaboxes before or after the ACF field groups.

    I added an options page with the slug of “test-options-page” and this is the result of my preliminary testing.

    
    <?php 
      
      new add_boxes_to_options_page();
      
      class add_boxes_to_options_page {
        
        public function __construct() {
          add_action('acf/input/admin_head', array($this, 'add_boxes_before'), 1);
          add_action('acf/input/admin_head', array($this, 'add_boxes_after'), 20);
        } // end public function __construct
        
        public function add_boxes_before() {
          $screen = get_current_screen();
          if ($screen->id == 'toplevel_page_test-options-page') {
            add_meta_box('custom-mb-before-acf', 'CUSTOM MB BEFORE ACF', array($this, 'callback_top'), 'acf_options_page', 'normal', 'high');
          }
        } // end public function add_boxes_before
        
        public function add_boxes_after() {
          $screen = get_current_screen();
          if ($screen->id == 'toplevel_page_test-options-page') {
            add_meta_box('custom-mb-after-acf', 'CUSTOM MB AFTER ACF', array($this, 'callback_top'), 'acf_options_page', 'normal', 'high');
          }
        } // end public function add_boxes_after
        
        public function callback_top($post, $args=array()) {
          ?><div><?php echo '<pre>'; var_dump($post); var_dump($args); echo '</pre>'; ?></div><?php 
        } // end public function callback_top
        
        public function callback_bot($post, $args=array()) {
          ?><div><?php echo '<pre>';  var_dump($post); var_dump($args); echo '</pre>'; ?></div><?php 
        } // end public function callback_bot
        
      } // end class add_boxes_to_options_page
      
    ?>
    
  • OK – not sure why, but ditching add_post_meta() / update_post_meta() in favour of ACF’s own update_field appears to work fine!

    add_action( 'load-post-new.php', 'wpse8650_post_new' );
    
    function wpse8650_post_new()
    { 
    	add_action( 'wp_insert_post', 'wpse8650_wp_insert_post_default' );
    }
    
    function wpse8650_wp_insert_post_default( $post_id )
    {
    
    	if ($_REQUEST["new_post_prefill"] == "yes")
    	{
              
               update_field('type', "Short conversation",  $post_id );
          
       	   update_field( 'customer', "Imaginary customer name",  $post_id  ); 
           
    	   update_field('parent_post', 1234,  $post_id ); 
    	   
        }
    
    }
  • James Stout from the ACF support was interested my problem.

    James’s answer maybe help for you too:

    This is likely as a result of having the save terms and load terms to post option enabled on the taxonomy field setting. With these options activated, the selected terms will be saved to the post and since all the rows are still on one post then they will be reflected. You can fix this by disabling this option.

    Thank You James.

  • Ok solved it alone, sharing here if ever someone needs it.

    function icon_avant_term( $title, $term, $field, $post_id ) {
            
            if(is_admin() && ("produits" == get_post_type($post_id)) ){
                
                $taxo = $title;
                $image = get_field('icone_liste_plus', $term);
                $title =  '<img src="'.$image['url'].'" /> ' . $taxo;
                return $title;
            
            }
    
        }
    
        add_filter('acf/fields/taxonomy/result/name=point_cle_produit_icon', 'icon_avant_term', 10, 4);
  • A few things, what exactly gets broken? You need to change the genesis hooks I gave you based on your theme. Example, if you footer is missing then the line that says remove footer you can remove it or just add “//” in front of that line.

    Second question, do your acf fields show up? If so then great, all you need to do is then fix the genesis hooks.

  • obviously Inline doesn’t work for me as well
    <div style="background-color:<?php the_field('color'); ?>">Something here...</div>

  • ETA:

    I’ve just found a similar issue with link fields. I get the following when I try to select a link

    Uncaught ReferenceError: wpLink is not defined
        at acf.Model.open (acf-input.min.js?ver=5.7.3:2)
        at i.onClickEdit (acf-input.min.js?ver=5.7.3:2)
        at i.<anonymous> (acf-input.min.js?ver=5.7.3:1)
        at HTMLAnchorElement.d (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,moxiejs,plupload&ver=5.0-alpha-43578:2)
        at HTMLDivElement.dispatch (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,moxiejs,plupload&ver=5.0-alpha-43578:3)
        at HTMLDivElement.r.handle (load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,moxiejs,plupload&ver=5.0-alpha-43578:3)

    Is this an issue with any ACF fields that open a modal?

  • Hello,

    I added the following code in page.php file but adding anything in that file breaks all my pages.

    // Remove Skip Links
    remove_action ( 'genesis_before_header', 'genesis_skip_links', 5 );
    
    // Dequeue Skip Links Script
    add_action( 'wp_enqueue_scripts', 'genesis_sample_dequeue_skip_links' );
    function genesis_sample_dequeue_skip_links() {
    wp_dequeue_script( 'skip-links' );
    }
    
    // Force full width content layout
    
    // Remove site header elements
    // remove_action( 'genesis_header', 'genesis_header_markup_open', 5 );
    // remove_action( 'genesis_header', 'genesis_do_header' );
    // remove_action( 'genesis_header', 'genesis_header_markup_close', 15 );
    
    // Remove navigation
    // remove_theme_support( 'genesis-menus' );
    
    // Remove breadcrumbs
    remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
    
    // Remove footer widgets
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    
    // Remove site footer elements
    remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
    remove_action( 'genesis_footer', 'genesis_do_footer' );
    remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
    
    // Remove page title
    
    // Remove site inner wrap
    add_filter( 'genesis_structural_wrap-site-inner', '__return_empty_string' );
    
    // Remove edit link
    add_filter ( 'genesis_edit_post_link' , '__return_false' );
    
    // Load landing page styles
    add_action( 'wp_enqueue_scripts', 'landing_do_tables_styles' );
    function landing_do_tables_styles() {
    wp_enqueue_style( 'tables', CHILD_URL . '/tables.css', array(), PARENT_THEME_VERSION );
    }
    
    //======================================================================
    // BEGIN ACF CONTENT
    //======================================================================
    
    add_action( ‘genesis_entry_content’, ‘ACF_content’ );
    function ACF_content() {
    	
    if( have_rows('content-block') ): ?>
    <div class="any-class-name">
    						
    <?php // loop through rows (parent repeater)
    while( have_rows('content-block') ): the_row(); ?>
    
    <div style="background-color:<?php get_sub_field('background_color'); ?>">
    <p><?php get_sub_field('content'); ?></p>
    </div>
    endwhile;
    
    else :
        // no rows found
    endif;
    </div>
    ?>	
    	
    <?php }
    //======================================================================
    // END ACF CONTENT
    //======================================================================

    I really appreciate your time and effort but unfortunately, I wasn’t able to make it work. Are there any changes that needs to be added in functions.php file because we have another website which uses ACF and the code is added in functions file.

    Regards,

    Ali

  • Oh ok I misunderstood, your initial response “in all my posts which are pages”. So for pages:

    1. Delete the single.php page, let’s start fresh again! 🙂
    2. move the page.php file to your child theme
    3. Add the following before “genesis()”, edit based on your theme style.
    // Remove Skip Links
    remove_action ( 'genesis_before_header', 'genesis_skip_links', 5 );
    
    // Dequeue Skip Links Script
    add_action( 'wp_enqueue_scripts', 'genesis_sample_dequeue_skip_links' );
    function genesis_sample_dequeue_skip_links() {
    wp_dequeue_script( 'skip-links' );
    }
    
    // Force full width content layout
    
    // Remove site header elements
    // remove_action( 'genesis_header', 'genesis_header_markup_open', 5 );
    // remove_action( 'genesis_header', 'genesis_do_header' );
    // remove_action( 'genesis_header', 'genesis_header_markup_close', 15 );
    
    // Remove navigation
    // remove_theme_support( 'genesis-menus' );
    
    // Remove breadcrumbs
    remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
    
    // Remove footer widgets
    remove_action( 'genesis_before_footer', 'genesis_footer_widget_areas' );
    
    // Remove site footer elements
    remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
    remove_action( 'genesis_footer', 'genesis_do_footer' );
    remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
    
    // Remove page title
    
    // Remove site inner wrap
    add_filter( 'genesis_structural_wrap-site-inner', '__return_empty_string' );
    
    // Remove edit link
    add_filter ( 'genesis_edit_post_link' , '__return_false' );
    
    // Load landing page styles
    add_action( 'wp_enqueue_scripts', 'landing_do_tables_styles' );
    function landing_do_tables_styles() {
    wp_enqueue_style( 'tables', CHILD_URL . '/tables.css', array(), PARENT_THEME_VERSION );
    }
    
    //======================================================================
    // BEGIN ACF CONTENT
    //======================================================================

    Now you need to add the Genesis hook to display your content so add the following code.

    ‘add_action( ‘genesis_entry_content’, ‘anyname_here’ );
    function anyname_here() {

    Here add your your acf code. Example below

    <?php }
    //======================================================================
    // END ACF CONTENT
    //======================================================================’

    It sounds like you are also not sure how to use the ACF code for a repeater field. I will give you and example code that you can then edit using the correct field name and html. I also recommend this page with more details https://www.advancedcustomfields.com/resources/repeater/

    Here is an example code you could easily change to your settings, you would add this to the code above.

    if( have_rows('your_repeater_field_name') ): ?>
    <div class="any-class-name">
    						
    <?php // loop through rows (parent repeater)
    while( have_rows('your_repeater_field_name') ): the_row(); ?>
    
    <div style="background-color:<?php get_sub_field('your_color_field_name'); ?>">
    <p><?php get_sub_field('your_description_field_name'); ?></p>
    </div>
    endwhile;
    
    else :
        // no rows found
    endif;
    </div>
    ?>

    I haven’t tested the above code, but this has a repeater field, color picker and textarea. You need to change the code field names (anything with “your_field_name” change) to match what you created in acf. Look at the documents for each field if you run into an issue. With this you should be able to get it working. If still not working then send a screenshot of your acf fields and send the code you are using. Good Luck!

  • I just created another post object field in the same form and that works fine: I can do a add_post_meta( $post_id, 'temporary_second_post_object_field', $_REQUEST['my_post_id'] ); and the field assumes that value with no problems!

    I suppose deleting the original field and recreating it might work, but I can’t really afford to do that, I’ve got hundreds of values in it that I’d have to painstakingly restore somehow…. also I suppose this might happen again any time.

    Could this be some obscure bug, then?

  • Hi Rociopts,

    Thank you for taking out time and responding back. Unfortunately, it didn’t work. Here is what I did:

    1) Copy single.php file from parent theme (genesis to child theme (business pro)
    2) Copied the 1st code excerpt you provided and pasted it before “genesis();” in the single.php file which now exists in child theme.
    3)Then I copied the 2nd part of code and pasted it in the same file.
    4) I replaced the content between strong tags with the acf code that I have posted in my 1st comment which starts like this *** Predefined Custom Fields ***/

    Just to give you a complete picture here is some further info
    – Business pro is my child theme while genesis is parent theme.
    – I am just trying to add an acf repeater field which includes a color picker and an editor for description.
    – These repeater fields are required on all PAGES. By pages I mean the PAGES that you see on the left sidebar of wordpress dashboard. These are different from POSTS which are blogs etc.

    Once again highly appreciate your effort.

    Regards,

    Ali

  • Did you get this to work? I had a similar problem that stumped me for days. Instead of:

    'value' => '"' . get_the_ID() . '"',

    this worked:

    'value' => get_the_ID(),

  • Well, I’m embarrassed. After reading the ACF source code I’ve found a display_errors function.

    To display the errors messages you just need to add it into the callback of the POST request, like this :

    $.post(
       my_ajax_obj.ajax_url, data,
       function(result) {
          errors = result.data.errors
          if (errors === 0) {
             // Code for success
          } else {
             acf.validation.display_errors( errors, $("form.acf-form") );
          }
       }
    );
  • Modifying the query to search for values in the title OR in meta fields is not an easy thing to do and cannot be done with the ACF filters alone. It requires making alterations to the “WHERE” portion of the query after it is constructed. http://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

  • Add the errors with the proper acf function :

    acf.validation.add_error(field_container, errors[i]['message']);

    field_container is the jQuery object of the .acf-field direct parent of the .acf-input

    errors[i]['message'] is the message (see how I get the errors in my previous post)

  • Hi Ally,
    Ok so it sounds like you need to edit your posts single.php file. Also, note that Genesis requires it’s own hooks.

    Any changes you made before like the plugins.php and to your functions.php etc…remove or save somewhere else, let’s start fresh.

    Next, copy to your child theme the file “single.php” and add the following before “genesis();” these are the hooks that you can turn on or off depending on your theme design, otherwise you will get just the content and no header, footer etc…:

    //* Force full width content layout
    add_filter( 'genesis_pre_get_option_site_layout','__genesis_return_full_width_content' );
    
    //* Removes the breadcrumb navigation
    remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' );
    
    //* Removes the post info function
    remove_action( 'genesis_entry_header', 'genesis_post_info', 5 );
    
    //* Removes the author box on single posts
    remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
    
    //* Removes the post meta function
    remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
    
    remove_action( 'genesis_loop', 'genesis_do_loop' );

    Now we have to add the genesis loop, where I say “anyname” change to a name that makes sense, so now add the following:

    //======================================================================
    // BEGIN ACF CONTENT
    //======================================================================
    add_action( 'genesis_loop', 'anyname_loop' );
    function anyname_loop() { ?>
    
    <article itemtype="http://schema.org/company" itemscope="itemscope" class="post-<?php print $pageid; ?> page type-page status-publish entry">
    <div class="entry-content" itemprop="text">
    
      <div class="co-wrapper">
    	<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    		<div class="co-title">
    			<h1><?php the_title(); ?></h1>
    		</div>
    
    <strong>Add your ACF content in here along with any html you want.</strong>
    
      </div>
    </div>
    </article>

    This should get you started with where to drop your acf code and your html.

    Lastly, if the site is live, I suggest testing this on a staging site or locally.

  • The error is happening in the acf-qtranslate, you should probably contact them about this error.

  • The only way to query a field that stores arrays is with “LIKE”

  • @philippbaschke the installer works great when I install as "type": "wordpress-plugin", but the admin menu doesn’t show up when I install as "type": "library". It seems like it’s not autoloading and/or enabling.

  • I think you have to use get_sub_field instead of the_sub_field

    function horairesEte() {
    	if( have_rows('horaires_ete', 'option') ):
    		while ( have_rows('horaires_ete', 'option') ) : the_row();
    			return '<span class="jours">'.get_sub_field('jours').'</span><span class="ouverture">'.get_sub_field('ouverture').'</span>-<span class="fermeture">'.get_sub_field('fermeture').'</span>';
    		endwhile; 
    	endif;
    }
    add_shortcode('horaires_ete', 'horairesEte');
  • Hi,

    It may be a stupid question but did you fill your custom fields in the post/page you want them to be ? Because your code is correct so it could be because of that.

  • I’m trying to run a query that only displays items that meet a condition in an Advanced Custom Fields select box, but I’m getting nothing. Here’s my query. Any help would be appreciated:

    <?php $args = array(
    ‘post_type’ => ‘home_plans’,
    ‘orderby’=> ‘date’,
    ‘order’ => ‘rand’,
    ‘numberposts’ => ’12’,
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘display_where’,
    ‘value’ => ‘here’,
    ‘compare’ => ‘LIKE’
    )
    )
    ); ?>

    <div id=”ms-container” class=”row archive”>
    <ul id=”posts_list”>
    <?php $recent_posts = wp_get_recent_posts( $args );
    $selected = get_field(‘display_where’);

    foreach( $recent_posts as $recent ){
    get_template_part( ‘template-parts/plan-archive-loop’, get_post_format() );
    }

    //wp_reset_postdata();
    ?>

    </div>

    Regards,
    from VidyaVox Jio4GVoice for PC

  • Hi,
    Could you try this…

    function horairesEte() {
    	ob_start();
    	if( have_rows('horaires_ete', 'option') ):
    		while ( have_rows('horaires_ete', 'option') ) : the_row();
    			return '<span class="jours">'.the_sub_field('jours').'</span><span class="ouverture">'.the_sub_field('ouverture').'</span>-<span class="fermeture">'.the_sub_field('fermeture').'</span>';
    		endwhile; 
    	endif;
    return ob_get_clean();
    }
    add_shortcode('horaires_ete', 'horairesEte');
Viewing 25 results - 9,326 through 9,350 (of 21,340 total)