Support

Account

Forum Replies Created

  • The use of $options['post_id'] produced an undefined error on options pages, so I would add an isset check:

    if ( $rule['value'] == 'woo_shop_page' && isset( $options['post_id'] ) )
  • Thanks @dangercode. I wanted the exact same thing. I used the docs and cheated by looking at your version. Here’s mine, a little shorter mostly bc of the closure.

    add_filter( 'acf/location/rule_values/page_type', function ( $choices ) {
        $choices['woo_shop_page'] = 'WooCommerce Shop Page';
        return $choices;
    });
    
    add_filter( 'acf/location/rule_match/page_type', function ( $match, $rule, $options ) {
        if ( $rule['value'] == 'woo_shop_page' )
        {
            if ( $rule['operator'] == '==' )
                $match = ( $options['post_id'] == wc_get_page_id( 'shop' ) );
            if ( $rule['operator'] == '!=' )
                $match = ( $options['post_id'] != wc_get_page_id( 'shop' ) );
        }
        return $match;
    }, 10, 3 );
  • Thanks John that tip solved it for me!

    In my case I’m placing the field groups on my production server with the json files and generating them from my local install. This way the client can’t edit them and I manage the fields through a git repo.

    So to get around this problem I’m making a copy of the field group json on site 12 (theme 12) and giving it to site 2 (theme 2). And then I change “active” to 0, this way the field is not displaying on site 2 but it is registered, and that seems to be enough for ACF to load the field contents from site 12 again! The one thing I have to aware of now is that I need to keep these files in sync when changing f.e. a label, and re-apply the “active” 0 difference.

  • I think I have the same issue. I have a repeater in the options area of site #12 and I can’t access it from site #2.

    
    // on site 12, works, displays all the data in the repeater
    print_r( get_field( 'featured_items', 'options' ) );
    
    
    // on site 2, only shows "6", the number of items in the repeater
    switch_to_blog( 12 );
    print_r( get_field( 'featured_items', 'options' ) );
    restore_current_blog();
    
    
    // on site 2, this is a text field, this works
    switch_to_blog( 12 );
    print_r( get_field( 'company_name_long', 'options' ) );
    restore_current_blog();
    
  • I’ve made some modifications so I’m not limited to a single get_field wrapper function, and you don’t have to put the filter code in your page template.

    <?php
    
    /**
     * functions.php
     */
    
    if ( !function_exists( 'yourprefix_acf_get_language_default' ) )
    {
        function yourprefix_acf_get_language_default()
        {
            return acf_get_setting( 'default_language' );
        }
    }
    
    if ( !function_exists( 'yourprefix_acf_set_language_to_default' ) )
    {
        function yourprefix_acf_set_language_to_default()
        {
            add_filter( 'acf/settings/current_language', 'yourprefix_acf_get_language_default', 100 );
        }
    }
    
    if ( !function_exists( 'yourprefix_acf_unset_language_to_default' ) )
    {
        function yourprefix_acf_unset_language_to_default()
        {
            remove_filter( 'acf/settings/current_language', 'yourprefix_acf_get_language_default', 100 );
        }
    }
    
    /**
     * page template
     */
    
    yourprefix_acf_set_language_to_default();
    
    // use any acf function like normal
    
    yourprefix_acf_unset_language_to_default();
  • I ran into the same issue. I got around it doing this: Visit the dashboard of every individual site, you should see an ACF dialog there as well but the button will read ‘Upgrade Database’ instead of ‘Review sites & upgrade’. Then click that. When you’ve done them all and return to the Network Admin Dashboard the notice there will be gone.

  • +1.

    A relationship field with only Users would be ideal.

    Making the Users field more like the relationship field with a search box and a clean view of all selected users would be alright too.

  • You could start by dumping the raw data that get_field gets for you and see if that matches your expectations in various scenerio’s (checked, unchecked, field not existing).

    I use a snippet like this to dump things (because I don’t like how var_dump() looks):

    echo "<pre style=\"text-align:left;padding:10px;border:1px solid red;background-color:#fff;color:#111;font-family:Courier;\">";
    print_r( get_field( 'featured' ) );
    echo "</pre>";
  • I regularly use the first image in the gallery for this. Depending on the site the first image is then also removed from the frontend photo gallery or slider itself if it is already shown separately on the same page.

    I do tell the owner of the site how this works but any site admin/editor/writer would figure out this logic when they first submit a draft or publish.

  • I think it might require an extra array. Try debugging with this code. Does the after print look right?

    add_filter( 'acf/fields/wysiwyg/toolbars', 'my_toolbars' );
    
    function my_toolbars( $toolbars )
    {
    	// dev
    	echo "<pre style=\"padding:10px;border:1px solid red;background-color:#fff;color:#111;font-family:Courier;\">";
    	print_r( "\n\n"."before we change stuff ▼\n" ); print_r( $toolbars['Basic'] );
    	echo "</pre>";
    
    	array_unshift( $toolbars['Basic'], 'forecolor' );
    
    	// dev
    	echo "<pre style=\"padding:10px;border:1px solid red;background-color:#fff;color:#111;font-family:Courier;\">";
    	print_r( "\n\n"."after we change stuff ▼\n" ); print_r( $toolbars['Basic'] );
    	echo "</pre>";
    
    	return $toolbars;
    }
  • Hey tigre. Your if ( get_field( 'btn_show' ) ); should be if ( get_field( 'btn_show' ) ):.

    The semicolon (;) ended the line so that’s why your else was “unexpected” according to PHP.

  • I’ve done this with get_post_type():

    <?php
    
    $rel_field_ids = get_field( 'rel_field' );
    $rel_field_ids_grouped = array();
    
    foreach ( $rel_field_ids as $rel_field_id )
    {
    	$post_type = get_post_type( $rel_field_id );
    	$rel_field_ids_grouped[ $post_type ][] = $rel_field_id;
    }
    
    ksort( $rel_field_ids_grouped );
    print_r( $rel_field_ids_grouped );
    
    ?>

    Code not tested.

  • Try

    <?php $clients = new WP_Query(array(
    	'post_type' => 'clients',
    	'posts_per_page' => -1,
    ));?>
  • You’re getting Array because they’re not all strings. You can convert those to a string like this:

    $fields = get_field_objects();
    if( $fields )
    {
    	foreach( $fields as $field_name => $field )
    	{
    		echo '<div>';
    			echo '<h3>' . $field['label'] . '</h3>';
    			
    			if ( is_array( $field['value'] ) )
    			{
    				echo implode( ', ', $field['value'] );
    			}
    			else
    			{
    				echo $field['value'];
    			}
    
    		echo '</div>';
    	}
    }
  • Open up the /plugins/woocommerce/templates dir. In there you’ll find content-single-product.php. In there you’ll find Woo actions being called and above each a list of hooks that the action contains. Find the hook that describes the area you want to add your custom fields to, for example woocommerce_template_single_excerpt. Then you Google that hook and on the docs.woothemes.com result you can click the link to ‘Located at’ file. On that page you search for woocommerce_template_single_excerpt. The function you arrive at will tell you the file used is single-product/short-description.php. Now you don’t want to modify this file directly, just like you don’t want to modify the WP core. Instead you copy plugins/woocommerce/templates/single-product/short-description.php to themes/YOURTHEME/woocommerce/single-product/short-description.php. Then you edit that file.

    I’m still working on my first WooCommerce website so I don’t know if this is the fastest way to find the template part you need but this is how I’m doing it.

  • I think I’d like this too. I’m still learning Woo and for now I just need 1 field so it’s no biggie, but I imagine ACF integrating with the Woo interface would be very helpful in keeping the UI clean when you’re doing more customization.

  • I’m about to run into the same limitation with my options pages. Pages and CPT items seem to work fine.

  • I had the same problem in a normal site. I updated to 5.0.1 manually. Then the in-WP update to 5.0.2 worked fine again.

  • Thanks for the code Sunrise. I just ran into the same problem.

  • I don’t necessarily see any errors in that code but you don’t have to do == true. Make sure you have the right field name and you are testing on a post/page that has content in there.

    You can also improve/clean up your code a bit. The code below is very readable but be careful not to use it too much or you wont easily see which endif belongs to which if.

    <?php if ( get_field( 'field_name' ) ): ?>
    
    This is displayed when the field_name is TRUE or has a value.
    
    <?php else: // field_name returned false ?>
    
    This is displayed when the field is FALSE, NULL or the field does not exist.
    
    <?php endif; // end of if field_name logic ?>
  • Hi Elliot.

    This thread looks very similar to what I’m looking for. My client wants a tag cloud that users can select items from (example), but also add new items with an input field. The cloud should be sorted by popularity and perhaps have a configurable limit.

    Hope this fits into your plans and maybe you can add it along the way.

    Sorry for the load of questions lately, this project is pushing my limits.

    Thanks!

  • Sweet! The Taxonomy field type too? I’m just going step by step. 🙂

  • Thanks Elliot! Looking forward to the update.

    If anyone desperately wants this right now I’m pretty sure you can do it with Admin Menu Editor Pro. The pro version lets you move menu items from sub to parent, the free doesn’t. I’m a big fan of the free version, it hides, moves and renames menu items, and might upgrade at some time.

Viewing 23 posts - 26 through 48 (of 48 total)