Elliot, Thanks!
This would be front end, inline JS so I can pull the custom fields for images.
I’m reading about the uniquid function and this looks like this will work. I’ll just need to setup a variable to use in both JS and PHP locations.
Thanks again.
Hi all,
I’ve double checked the settings, and it’s all exactly the same as before.
The custom post type is set to ‘post’, just like my other sites.
(The actual post types and fields are made up exactly the same as I’m using the same data/layouts).
MID-SENTENCE-UPDATE:
Found the issue, there’s an incompatibility with the plugin “Role Scoper”.
I’m not sure what the nature of the incompatibility would be though as I’m not that great a back-end coder. I’ll see if I can check, though it would be sad if I can’t find a way to utilise both plugins as they’re equally important.
-J
Okay, this is what I did;
<?php $summary = get_field('description');
echo substr($summary, 0, 200); ?>
That does what I require, thanks.
Hello, I think I have the same problem, I’ve made a website in march 2013 using ACF. In this website, I’ve created a custom post type ‘product’ containing 270 posts. In one ACF Group, I put a rule to show the group to only two posts from product. It’s working fine, but, I’d like to add one new post in the rule and now, my product posts are not shown anymore. The two previous rules are working but don’t show the good info (ex: Post > is equal to > ‘first post of the list’*). *and the list don’t show anymore my products.
Following the topic here, I checked the registering of my custom post type and at the ‘capability_type’ line, I used this term : ‘content_editor’ accordingly to work with a plugin called ‘map cap’. I deactivated this plugin a put ‘post’ in place of content_editor and it did the trick.
Now I have to find a way to reactivate ‘Map Cap’. It’s a plugin to manage the right on user types following the custom post types.
Hi Elliot,
Here’s the code – thanks!
<!-- BEGIN .entry-content -->
<div class="entry-content">
<p style="margin-bottom: 1rem"><img style="vertical-align:middle;margin-left:10px" src="http://new.cesi.ie/wp-content/uploads/2014/01/presentation-icon.png" /> = Presentation<img style="vertical-align:middle;margin-left:10px" src="http://new.cesi.ie/wp-content/uploads/2014/01/workshop_icon.png" /> = Workshop</p>
<?php the_content(); ?>
<?php g1_wp_link_pages(); ?>
<?php if(get_field('event_programme')): ?>
<div id="g1-table-1" class="g1-table g1-table--solid ">
<?php while(has_sub_field('event_programme')): ?>
<table>
<caption><h2><?php echo date('l, M jS', strtotime(get_sub_field('date'))) ?></h2></caption>
<?php if(get_field('event_programme')): ?>
<?php while(has_sub_field('event_details')): ?>
<thead> <tr> <th colspan="3">
<?php the_sub_field('start_time'); ?> - <?php the_sub_field('end_time'); ?>
</th> </tr> </thead>
<?php if(get_field('event_programme')): ?>
<?php while(has_sub_field('presentation_details')): ?>
<tbody> <tr><td>
<?php
$type = get_sub_field(‘event_type’);
?>
<i class="icon-<?php echo $type; ?>"></i></td>
<td><strong><?php the_sub_field('title'); ?></strong><?php the_sub_field('speaker'); ?></td>
<td><?php the_sub_field('location'); ?></td></tr>
</tbody>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?> </table><p></p>
<?php endwhile; ?></div>
<?php endif; ?>
</div>
<p><?php echo do_shortcode("[feather_share]"); ?></p>
<!-- END .entry-content -->
great, thanks that works 🙂
<?php if(get_field("downloads")): ?>
<div id="downloadbox">
<h3>Files</h3>
<ul class="downloads">
<?php while(the_flexible_field("downloads")): ?>
<?php if(get_row_layout() == 'flexible_download'): // layout: Content ?>
<?php $attachment_id = get_sub_field('file');
$url = wp_get_attachment_url( $attachment_id );
$title = get_the_title( $attachment_id );
// part where to get the filesize
$filesize = filesize( get_attached_file( $attachment_id ) );
$filesize = size_format($filesize, 2);
// part where to get the extension
$path_info = pathinfo( get_attached_file( $attachment_id ) );?>
<li class="cf dlbox">
<a href="<?php echo $url; ?>" class="cf">
<span class="dl-title"><?php echo $title; ?><small><nobr><strong>Size:</strong> <em>(<?php echo $filesize; ?>)</em></nobr></small></span>
<span class="dl-extension"><span class="dl-extension-inner"><?php echo $path_info['extension']; ?></span></span>
</a>
</li>
<?php endif; endwhile; ?>
</ul>
</div>
<?php endif; ?>
Cool cool cool – thanks a lot!!! Works fine now! But your answer also brought up a bit of a dumb follow up question i suppose. I query two repeater fields in this example – one text and one image repeater field. Why do I have to use the_subfield on the text field:
<li><?php the_sub_field( 'pro_service_single' ); ?></li>
and get_sub_field on the image field?
<?php $projectimages = get_sub_field('pro_impressions'); ?>
Is it cuz the second query is about an image object which gets passed to an array and the first is just a plain query? Thanks again for the fast response and help. Best regards Ralf
Hi @rdck
It is not possible for a location or conditional logic rule to detect a value from another field group.
The only thing I can think of is changing the logic around so that instead of selecting the ‘featured’ posts from the home page, you tick a checkbox on the post you want featured.
This way, once you check this box, you can have conditional logic show some more image fields, etc.
You will need to change the code in your home page template, to query all posts and find the ones which have this checkbox ticked. You can find some code examples for this on the true_false
docuemntation page.
Hope that helps.
Thanks
E
Hi @smspaul
Thanks again for your work today on the support forum. I just read over your question again, and think I can help a bit more.
Using the get_field_objects will get you all your repeater fields, this is good and perhaps I oversaw the usefulness.
I can see what you are doing wiht your setup and I would like to say firstly, that the flexible content field will do all this for you and probably save you some dev time!
That aside, to sort the data, you will need to merge all the rows together into 1 array like so, and then sort them:
<?php
$rows = array();
$fields = get_field_objects();
if( $fields )
{
foreach( $fields as $field )
{
$field_label = $field['label'];
$field_name = $field['name'];
// loop through repeater rows
if( $field['value'] )
{
foreach( $field['value'] as $row )
{
// add extra data to row
$row['field_label'] = $field_label;
$row['field_name'] = $field_name;
// append row
$rows[] = $row;
}
}
}
}
// test all rows of data
echo '<pre>';
print_r($rows);
echo '</pre>';
die;
// sort rows
$order_by = array();
foreach( $rows as $i => $row ) {
$order_by[ $i ] = $row['order'];
}
array_multisort( $order_by, SORT_ASC, $rows );
// test sorted rows
echo '<pre>';
print_r($rows);
echo '</pre>';
die;
?>
Hope that helps.
Cheers
E
Hi @emaildano
Is this on the front end in a template?
Is the JS inline with the template?
You can create a unique ID from many things such as the time, name or even field value. If both the HTML and JS are being generated in the same file, you can match the ‘selector’ quite easily.
I prefer to use the function uniqid
– which will give you a very unique number.
Thanks
E
Going back to the original code, there are quite a few syntax errors. Firstly, can you please read over the repeater field documentation to better understand how the has_sub_field to have_rows loops work?
I think @Jamie code will work for you, however, the sub field name looks wrong. Just change $attachment_id = get_sub_field('illustrations_image');
to your field name $attachment_id = get_sub_field('gimages');
I am amusing that gimages is your sub field name.
Perhaps you could also post a screenshot of the edit page showing the repeater field and it’s sub fields? Also, please list the correct field names.
Thanks
E
Hi @ygesit
A quick Google showed a plugin to add in an expiry date:
http://wordpress.org/plugins/post-expirator/
Thanks
E
Hi @noxoc
Thanks for the question. Using the repeater field, it will not be possible to query the data as you have asked.
However, it is possible to do so using a plugin called posts 2 posts
. This will replace the repeater field on the clients CPT and allow you to connect the client to work.
Then you can use normal WP_Query to get the posts. The posts 2 posts
plugin contains new parameters for the WP_Query so you can ask for posts that are connected to works and then also add in the work tax_query.
It will be a bit tricky, but it will be possible.
Thanks
E
Hi @rpk
Thanks for the code. The issue may be as simple as changing:
$projectimages = the_sub_field('pro_impressions');
to
$projectimages = get_sub_field('pro_impressions');
Make sure all the field names are correct, and this should work just fine.
As for the wp_reset_postdata()
function, this is a WP function only to be used after a custom WP_Query loop, not a repeater field loop.
Thanks
E
@elliot:
This is what a noob I am: I didn’t realize you could actually make custom posts appear on ANY page you wanted just by using a query on that page. I thought you had to use one special page to make them show up, and I couldn’t figure out what that mythical one special page was. Now I understand much better how this plugin works, and it blows my mind even more. Thanks for making it!
In this situation, you could try something like this:
http://stackoverflow.com/questions/12444945/cut-the-content-after-10-words
Yes that’s correct but I have meta boxes from other plugins that also have their priority set to high and I would like to have all afc meta boxes last.
It would have been a quick fix if I could have filtered the priority to low, but after a closer look it seems like that’s not possible.
Do you know of any other way to achieve this? I was thinking about removing them with remove_meta_box() and then add them again with add_meta_box() but would that be safe?
That’s right. I have built a relation like herehttp://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/ but it seems not to work at all..
Hi @jirih,
I am not quite sure what the problem is here. Can you please elaborate?
Hi @davidzumini,
The meta query does not use the epoch time format. Have you tried using he WordPress date function? Eg:
$today = current_time('mysql');
Hi there, what you’re trying to do could be achieved with a built-in PHP function.
Check out this article:
http://stackoverflow.com/questions/173868/how-to-extract-a-file-extension-in-php
You would declare a variable to use as the file extension. Something like:
$ext = pathinfo($url, PATHINFO_EXTENSION);
Reference: http://php.net/manual/en/function.pathinfo.php
Hi there, I’ve run into similar issues. This article helped me out a lot:
http://stackoverflow.com/questions/936242/php-how-do-you-determine-every-nth-iteration-of-a-loop
You’ll need to start a counter just above your while loop:
$counter = 0;
You should be able to drop an if statement into your while loop:
if ($counter % 4 == 0) {
// code here
}
Then just before your closing endwhile; you’ll need to advance the counter:
$counter ++;
The if statement will evaluate to true every 4 iterations of the loop.
You’ll need to use wp_get_attachment_image if your using the ID – maybe something like below – havnt tested but hopefully it’ll work
<?php
if(get_field('image_gallery')): ?>
<?php while(has_sub_field('image_gallery')): ?>
<?php
$attachment_id = get_sub_field('illustrations_image');
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
$imageurl = wp_get_attachment_image_src( $attachment_id, 'full' );
$image_title = $attachment->post_title;
?>
<a href="<?php echo $imageurl[0] ?>" title="<?php echo $image_title; ?>"><?php echo $img; ?></a>
<?php endwhile; ?>
<?php endif; ?>
Hi @SimonPrice
You will need to track down where this inline JS code is comming from and either remove it or wrap it in a:
jQuery(window).load(function(){
});
Thanks
E
Gosh, thanks! That’s so clear. I think I removed the $post_id check based on another tutorial blog post, so the answer to my current issue wasn’t appearing to me. Now that you’ve told me, I realize it’s quite clear. Thanks so much for the help.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.