Support

Account

Forum Replies Created

  • Hi,

    Yes you’d have to write out the code for all the places where you have images. If you have the images in a repeaterfield you do not however.. If you’re looking to create an gallery I’d suggest you take a look at the gallery field add on. With that you retrieve the alt text per default.

    If you prefer you could just create a function for this to simplify your code in the template. Put this in functions.php

    
    function get_image_with_alt($imagefield, $postID, $imagesize = 'full'){
    $imageID = get_field($imagefield, $postID); 
    $image = wp_get_attachment_image_src( $imageID, $imagesize ); 
    $alt_text = get_post_meta($imageID , '_wp_attachment_image_alt', true); 
    return '<img src="' . $image[0] . '" alt="' . $alt_text . '" />';
    }
    

    And then all it like this where you want the image in your template:

    
    <?php echo get_image_with_alt('NAME OF THE IMAGE FIELD', get_the_ID(), 'thumbnail'); ?>
    

    Note that the last parameter in the function is optional and it’s for if you want another image size than full.

  • Well if you just take a look at where ACF saves the image field for the optionspage you should be able to do a set_option or add_post_meta depending on if it’s in wp_postmeta or wp_options..

    However a different solution you could do is to have an if statement around the output of the logo (this assumes that the return is set to image URL):

    
    <?php
    if(get_field('custom_logo_field', 'options')){
    $image = get_field('custom_logo_field', 'options');
    }else{
    $image = get_bloginfo('template_directory') . 'images/default-logo.png';
    }
    ?>
    <img src="<?php $image; ?>" alt="company name" id="logo" />
    
    
  • Hi,

    I assume you mean the file field in ACF.. From what I know the file field has never supported automatically creating an preview image. The image field does however but that is for images only.

  • Hi Jean,

    Yes the repeaterfield can contain the gallery field.. I don’t think there’s any restrictions in terms of the repeater and flexible fields capabilities.. atleast not that I’ve discovered and I would like to think that I’ve used pretty much any combination by now 🙂

  • I think you could just create the post meta data upon activation.. since it’ll have the correct meta key the options image field should recognize it and it’d be set as “default” from the users point of view..

    Altho I’m not sure where the options page saves it’s data.. if its in the wp_options table you’ll need to use set_option

  • Or you can also create a regular page called “translations” where you might put all strings in as acf textfields. Then you’ll be able to translate it as usual pages and it’s a bit simpler than creating a whole cpt for a single page 🙂

    I usually create three pages when dealing with WPML and ACF; Header, Footer and Global translations. These three act as replacement for having three options-pages with ACF. The upside is that they’re all collected in pages for easy access and you don’t need to create a cpt. The downside is that it’s not really semantically correct since they are not really being used as pages.

  • Hey,

    Alright I suppose you’re right.

    Yes I can do some debugging in the relationship field. It does not seem to work too well with print_r and die tho but setting all debugging to true I can do it a bit differently.

  • Alright..

    I tried changing the get_pages to a wp_query and setting the numberposts to 100 which then workes.. So I’m guessing that this has to do with the clients site actually having such a monstrous amount of pages.

    My solution to this was to change the post link field to a relationship field since that uses ajax and does not have to fetch all posts at once.

    There’s a new issue with the relationship field tho that I’ll post in a new topic to not clutter things up.

  • have you switched out ‘myfieldname’ for your relationship fields name?

  • Hi @elliot,

    You’re probably right.. however I’m having difficulties debugging the field type. Nothing is being registered in the debug.log file. Probably since it’s being loaded with ajax and the ajax call works..

    The only error I get is this js-error: Uncaught TypeError: Object [object Object] has no method ‘sortable’

    But I’m pretty sure that’s due to the wysiwyg script not loading since the post object field disrupts the loading.

    Do you have any tricks to get the field to output errors? I’ve tried doing print_r with a die(); right after but there’s no output anywhere.

    EDIT:

    Okay so I tried disabling all other plugins with no luck, so I guess that’s not the issue.. I did manage to get this error at the place where the field should have appeared in page edit: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/qa.nord-lock.com/wwwroot/wp-includes/wp-db.php on line 1225
    which I suppose makes your guess for it to be a loop correct. Now I just have to figure out why the hell its looping..

  • I’m a self-taught developer myself 🙂 I think it’s quite common in our line of work..

    Sorry I think this is more like it:

    
    if (!empty($_GET['company'])) {
        // we got company....
    }
    

    The URL you are directed to is probably not correct if you’re supposed to end up on the regular posts archive.. You can try switching the $archive variable out and replace it with a “hardcoded” url to the archive page.. Right not it seems like it’s trying to go to the archive of companies.

  • Hi Nataliette (cool name)

    You can limit the number of posts by adding ‘posts_per_page’ => 5
    to the query. Change 5 to whatever number you want.

    As for setting a view more link that’s a bit more complicated since there’s no default archive for posts queried by meta value. I suppose you could do something like this:

    
    <?php 
    $company_ID = $post->ID; //get the id of the current company
    $archive = get_post_type_archive_link('post').'?company='.$company_ID;
    ?>
    <a href="<?php echo $archive; ?>">Read more</a>
    

    This would mean that when you click the read more you get sent to the regular post archive but with an GET parameter.. Then on archive.php you can do a check for this parameter and if it’s present query all posts with that meta value.

    
    if(isset($_GET['company'])){
    
    }
    
  • Hi Damian,

    You have to edit the template files in which you want the gallery to appear. Have a look at the documentation for the field: http://www.advancedcustomfields.com/resources/field-types/gallery/

  • No worries dude, glad to help.

    Well i suppose this method is quite alright if you use a specific page template for those pages to make sure the query is not run on uhnecessery pages..

    One thing which would make it easier for you would be if you could have a select on the products which is automatically filled with the pages from that specific page template. This does not exist in ACF atm from what I know..

    IF you’re by any chance using ACF v3 I have created such a field which you can find here:
    https://github.com/jonathan-dejong/ACF-Pages-by-Template

    Unfortunately it doesnt work on v4 but you’re free to fork it and convert it to v4 if you like 🙂 Atleast you’ll have a lot of work done.

  • I can’t say 100% since I’m not that good at SQL.. but I think that LIKE means that it could be a string within a string.. It’s better that you google it.. “SQL LIKE”

    orderby meta_id does not work.. if you want to order them by their ID you can just set orderby => id ..

    default is date, but I’m guessing you’d want to order them by title?

    orderby => title ..

    anyway, you can find all orderby values here: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

  • It’d be a nice feature indeed.. I can see how it’d be a bit harder to implement tho since the logic would have to check for just the other fields in that particular “repeat”.. I can also imagine it’d be a bit slow on huge repeaters

  • Hi!

    Your logic is a bit backwards but it’ll still work.. So what you want is to display the products which are “connected” to a page being viewed.. unfortunately there’s no way to do this query on just those four pages (unless they use a custom template file) but you can do something like this on the page template:

    
    <?php
    $args = array(
    'post_type' => 'products',
    'posts_per_page' => -1,
    'meta_query' => array(
    		array(
    			'key' => 'make_partner_featured',
    			'value' => "$post->ID",
    			'compare' => '='
    		)
    	)
    );
    $products = new WP_Query($args);
    if($products->have_posts()): while($products->have_posts()): $products->the_post();
    
    //Show title
    the_title();
    
    endwhile; wp_reset_postdata(); endif;
    ?>
    

    Put this is your page template file and it’ll query your products when visiting a page and if the products ACF field value corresponds to the current pages id they will be fetched and the title of the product will be output.

    It’d be better to just do this when you know you’re on one of the pages in question and not all pages.. you can solve this by either giving them a custom page template or by a simple if statement around the code checking the current pages id against the four ids you have.. The second solution isn’t dynamic tho since you’d have to add another pages id in the if-statement if you want it to have the same feature..

  • seriously.. marked your own thanks as the solution? =P

  • It’s probably a JS error.. if you have chrome or firefox you can check your console for js errors and post them here! It’d help!

  • Hey dude!

    I think that if you want to do this you’d have to go into the relationship field file and add the functionality. It shouldnt be too hard since Elliot has already added a filter by post type..

    If you want it to stay “clean” you can copy the field to your theme, rename it and do the changes there and thus creating a custom relationship field beside the regular one.

  • Hi guys!

    In regards to Davids request to be able to duplicate. Since the fieldgroups are basically posts you can actually use this plugin:
    http://wordpress.org/plugins/duplicate-post/

    I’ve tried it myself on a fieldgroup containing repeaterfields and other fields with success so I think it’d work fine on any fieldgroup.

    Perhaps this could be added to the documentation so that everyone and not just ppl finding their way here become aware of this 🙂

  • Hi Tracy,

    First of, get_the_title does not take any other parameter than the ID of the post in question..

    What you’re asking for in your first post is the alt text that you’ve put into the image editor in the media library. This is not really part of ACF but is a standard WP thing.

    So assuming that the field you’ve wrote in for each image is indeed the alt field your code should look something like this:

    This assumes that what you have created in ACF is an image field where you have set the return value to be the images id.

    
    <?php $imageID = get_field('THIS IS YOUR FIELD NAME FOR THE IMAGE'); ?>
    <?php $image = wp_get_attachment_image_src( $imageID, 'full' ); ?>
    <?php $alt_text = get_post_meta($imageID , '_wp_attachment_image_alt', true); ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt_text; ?>" />
    
    
  • I agree of course.. from Elliots point of view that would probably mean that he’d have to make some sort of ajax validation check when the user saves a fieldgroup.. not impossible but tbh, I’d rather he focus on other areas of improvement since the use of the API and PHP is far less used than the admin interface and it still works as is.

    Perhaps something to develop on an github fork?

Viewing 25 posts - 976 through 1,000 (of 1,019 total)