Support

Account

Forum Replies Created

  • Updated local.php works, thanks Elliot. Yes we register the fields via php (and load the plugin from within the theme folder).

  • Thanks John! Only the content area is secured. Header and footer is the same as the rest of the site (which is public). Yeah i think this is a save solution ๐Ÿ™‚ . ACF is so great … .

  • Ummmmmm – just forgot it’s a post_object field ๐Ÿ˜‰ – now it works, thank you john!

  • “The have_rows() function will return false when loading a cloned sub field using the โ€˜Display = Blockโ€™ setting. Please note that using the โ€˜Seamlessโ€™ display setting will allow sub have_rows() loops to work as expected.”

    https://www.advancedcustomfields.com/resources/clone/

    I hope an update will “fix” this.

  • This was fixed, it is working now ๐Ÿ™‚

  • This works for backend but in frontend I still have the error.

  • Could you tell me what is the difference between “object” and “ID” in custom fields?

  • Hi John, this works, awesome! (when i add a “y” behind “taxonom”).

  • This gives me the term_link, but still the name is not shown:

    <?php if( have_rows('bilder', 'option') ): ?>
    <ul>
    <?php while( have_rows('bilder', 'option') ): the_row(); 
    	// vars
    	$image = get_sub_field('bild');
    	$category = get_sub_field('kategorie');
    	?>
    
    	<?php
    	$terms = get_sub_field('kategorie');
    	if( $terms ): ?>
    	<?php foreach( $terms as $term ): ?>
    		<?php echo get_term_link( $term ); ?>
    		<?php echo $term->name; ?>
    	<?php endforeach; ?>
    	<?php endif; ?>
    
    	<li>
    		<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    	</li>
    <?php endwhile; ?>
    </ul>
    
    <?php endif; ?>
  • This little snippet worked for me:
    <?php echo count( get_field('features') ); ?>

    ๐Ÿ˜‰

  • Hello John,
    I already tried this but when i do this i get:

    <div>1</div>
    <div>2</div>
    <div>3</div>

    but i need:

    <div>3</div>
    <div>3</div>
    <div>3</div>

    or

    <div>2</div>
    <div>2</div>

    or

    <div>1</div>

    Means: Count all flexible rows and give the number to every row (DIV in this case).

  • sorry i can not check it because i am not at work. if i remember right “download_list” is a flexible content field, “download” is a repeater field and “singledl” is the file field.

    flexible content > repeater > file.

  • With this you get the extension, too:

    get it:
    $path_info = pathinfo( get_attached_file( $attachment_id ) );

    show it:
    echo $path_info['extension']

    full example with a repeater field (to show some downloads):

    <?php
    // Downloads repeater field
    if (get_row_layout() == 'download_list'): ?>
    <?php if(get_sub_field('download')) { ?>
    <ul class="unstyled downloads">
    <?php while(has_sub_field('download')) {
    $attachment_id = get_sub_field('singledl');
    $url = wp_get_attachment_url( $attachment_id );
    $title = get_the_title( $attachment_id );
    $filesize = filesize( get_attached_file( $attachment_id ) );
    $filesize = size_format($filesize, 2);
    $path_info = pathinfo( get_attached_file( $attachment_id ) ); 
    ?>
    <li class="table">
    <a href="<?php echo $url; ?>" class="download table-row break">
    <span class="icon-download2 iconF icon-20 icon-fl" aria-hidden="true"></span>
    <?php echo '<span class="filetitle table-cell">' . $title . ' (' . $path_info['extension'] . ')</span>' . '<span class="filesize table-cell">' . $filesize . '</span>' ?>
    </a>				
    </li>
    <?php } ?>
    </ul>
    <?php } ?>	
    <?php ?>
  • This code works for me, no plugin needed:
    https://gist.github.com/charleslouis/5924863
    (put code in functions.php).

  • Oh I’m quite happy with the solution. Only drawback is that the customer has to type a “ยฉ” when he wants to put copyright information, but I think that shouldn’t be a big deal ๐Ÿ˜‰ .

    The code above is more like copy pasted from here and there, fiddling around and see what happens, but when i reach a point at which I know there is no better way than standard wordpress/ACF solutions I am mostly happy with that because I know it is the best possible solution, and โ€ฆ I learned a little, maybe it helps in other situations in future ๐Ÿ˜‰

  • I ended up using the regular caption field.

    It is no problem to show the attachment custom field under article thumbnails or gallery images, but if you put this field to the regular caption of images used to put in the tinyMCE there are some drawbacks:

    – you have to do “disable_captions” (and then generate your own …) – that deletes the regular caption field from the editor ๐Ÿ™
    – the ACF attachment meta field is not available in the image editor, you have to go the library and edit the image information there to add content to the ACF field

    This is confusing I think. Now i added the regular caption to the gallery and the post thumbnails.

  • I thought there could be a ACF function or something. Now I did it with a normal custom field and put it to the caption. For this I had to disable the caption and made a custom caption:

    // add copyright to caption function
    //////////////////////////////////////////////////////////
    // add custom field to image editor
    add_filter("attachment_fields_to_edit", "add_image_copyright", 10, 2);
    function add_image_copyright($form_fields, $post) {
    	$form_fields["copyright"] = array(
    		"label" => __("Copyright"),
    		"input" => "text",
    		"value" => get_post_meta($post->ID, "copyright", true),
    		"helps" => __("(Das \"&copy;\" Zeichen wird automatisch hinzugef&uuml;gt)"),
    	);
     	return $form_fields;
    }
    add_filter("attachment_fields_to_save", "save_image_copyright", 10 , 2);
    function save_image_copyright($post, $attachment) {
    	if (isset($attachment['copyright']))
    		update_post_meta($post['ID'], 'copyright', $attachment['copyright']);
    	return $post;
    }
    
    // caption function for regular caption and copyright field
    // disable regular caption and build a custom one
    add_filter( 'disable_captions', create_function('$a', 'return true;') );
    function image_send_to_editor_2($html, $id, $caption, $title, $align, $url, $size, $alt) {
    
        $width = 'auto';
    
        if ( preg_match( '/width="([0-9]+)/', $html, $matches ) ) {
            $width = $matches[1] . 'px';
        }
    
    	// Extract attachment $post->ID
    	preg_match('/\d+/', $id, $att_id);
    	if (is_numeric($att_id[0]) && $copyright = get_post_meta($att_id[0], 'copyright', true)) {
    		$cright .= '<span class="caption-customfield">&copy;&nbsp;' . $copyright . '</span>';
    	}
    
        $output = '[caption id="attachment_' . $id . '" align="align' . $align . '" width="' . $width . '"]';
        $output .= $html;
        $output .= $cright.'<span class="caption-regular">'.$caption.'</span>'.'[/caption]';
    
        return $output;
    }
    
    add_filter('image_send_to_editor', 'image_send_to_editor_2', 10, 8);

    This is the output:

    <div id="attachment_1312" style="width: 310px" class="wp-caption alignleft">
    
    <img class="alignleft size-medium wp-image-1312" src="http://localhost:8888/mywebsite/wp-content/uploads/2015/09/download102-300x225.jpg" alt="download10" height="225" width="300">
    
    <p class="wp-caption-text">
    	<span class="caption-customfield">ยฉ&nbsp; Name of Photographer</span>
    </p>
    
    </div>
  • Okay i will try that, but as far as I know now, after googling a lot, the only way is to put it in the caption field, because otherwise wordpress will not put html to the image. I found one (very old) plugin that does it this way.

  • LOL, replacing

    get_post_meta( $post->ID, 'copyright', true )

    with

    get_post_meta( $image['id'], 'copyright', true )

    did the trick.

    But why does <?php var_dump(get_field('gallery')) ?> not work?

  • Okay this works, just adding “capability” (https://codex.wordpress.org/Roles_and_Capabilities) to the sub-pages.

    acf_add_options_sub_page(array(
    	'page_title' 	=> 'Colors',
    	'menu_title'	=> 'Colors',
    	'parent_slug'	=> 'theme-general-settings',
    	'capability'	=> 'manage_options',
    ));

    Aaah, and 'position' => 2, works, too ๐Ÿ™‚

  • shure that file is in the theme. i have build my own theme, i have exportet the custom fields and put it in the functions.php file within my theme (for version control on installed themes). the labels of the custom fields have umlauts. it’s no problem with the website at all but i wonder that the theme checker tells me this is an error.

  • johann this is awesome!

Viewing 25 posts - 26 through 50 (of 94 total)