Hi
I use if (++$i == 2) break;
to stop the loop at 2 rows. EG.
if( $rows ) {
$i = 0;
foreach( $rows as $row ) {
if (++$i == 2) break;
endif;
}
So you can change the 2 to a 6 to limit the number of values returned.
Hope that helps!?
Sure.
I’ve installed the timthumb code in its own directory within my theme.
I then have a field within my repeater called image
Finally, I have a line of PHP ($theme_path) which I call from my function file. This is simple the path to timthumbs files like so:
$theme_path =’http://www.domain.co.uk/wp-content/themes/theme_folder/’;
<img src="<?php echo $theme_path; ?>timthumb/timthumb.php?src=<?php the_sub_field('image'); ?>&w=618&h=298&q=100">
That should get you what you need. Hope that helps
Daft question!
How can I get the uploaded image into the JS script?
Am massively struggling so any help is very much appreciated
Thanks
Hi,
Can you not use TimThumb? This is what I do and it works really well!
A-ha! Yes I have that lol
Ok I will try again
Thanks again.
I don’t have a html field though? Running the latest version and can’t see it. 🙁
Thanks Jonathan
Actually, this isn’t as easy I first thought.
Is it even possible to add an A tag within the repeater? I tried using a text field and the append option
Something is telling me this is going to be a headache 🙁
Oh I see! Sorry, that makes sense now with regards to the a-tag (feeling embarrassed)
I think this is coming together, my only concern is how to pass the X and Y value back from the pop up window to the repeater row.
Otherwise I think this is all the pieces needed.
Again, if anyone has any thoughts on this, please feel free to contribute. It would be good to get this available to all as I’m sure I can’t be the only one that needs this?!
Thanks Jonathan
I’m sort of new to the ACF plugin. What does the -tag do?
Would you not need to publish the post in order to view the image in order to have something to click to get the coordinates?
Any code input is most welcome as I can’t work out where on earth to start. In my head it seems ok but trying to put it into code seems to be a right mare!!
OK,
I’ve been giving this some thought and think I can work out the stages but need help with the code
1) So you create a new post
2) Upload an image to the custom field: Image
3) Publish
4) Ideally once published then a repeater field appears (is that easy to do?)
5) The ACF repeater has:
– Caption
– URL
– X coordinate
– Y coordinate
6) At the end of the repeater row you can click to open a pop up
7) The pop up window contains this script but shows the image from the published post
8) You click the image and to get an X and Y value
9) These are then passed back to the repeater
Am I over complicating this? Is there an easier solution?
Any help is very much appreciated
Can you not simply use the first row of the repeater:
<?php
$rows = get_field('repeater_field_name' ); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['sub_field_name' ]; // get the sub field value
// Note
// $first_row_image = 123 (image ID)
$image = wp_get_attachment_image_src( $first_row_image, 'full' );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" />
Taken from here: Repeater Documentation
Ok, managed to solve it by swapping the SQl round a little, like so:
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM wp_postmeta
WHERE meta_key LIKE %s AND meta_value LIKE %s ORDER BY meta_value ASC",
'dates_%_available_dates', ''.$year.''.$month.'%',
""
));
Ok, this now works as I need it. I wonder if the code can be tidied in anyway but it works. Here’s my code incase it helps anyone else.
<?php
#start from current month. Change 6 to however months ahead you want
for ($x=0; $x<=6; $x++) {
$date = new DateTime("$x months");
$date->modify("-" . ($date->format('j')-1) . " days");
#echo $date->format('j, m Y');
$month = $date->format('m');
$year = $date->format('Y');
#echo 'Month= '.$month .' Year= '.$year.' <br>'; #debug
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM upKeep_postmeta
WHERE meta_key LIKE %s
AND meta_value LIKE %s
",
'dates_%_available_dates', // meta_name: $ParentName_$RowNumber_$ChildName
#''.$year.''.$month.'%' // meta_value: 20131031 for example
''.$year.''.$month.'%' // meta_value: 20131031 for example
));
// loop through the results
if( $rows ) {
echo '<h2>'.$date->format('F').' '.$date->format('Y').'</h2>';
echo '<ul>';
foreach( $rows as $row ) {
// for each result, find the 'repeater row number' and use it to load the sub field!
preg_match('_([0-9]+)_', $row->meta_key, $matches);
$meta_key = 'dates_' . $matches[0] . '_dates'; // $matches[0] contains the row number!
?>
<li><a href="<?php get_permalink( $row->post_id ); ?>"><?php echo get_the_title( $row->post_id ); ?></a></li>
<?php
}
echo '</ul>';
}
}
?>
Thanks @elliot for the reply.
I’ve started to look at the SQL method as I think this may work, however, I’ve come unstuck with the code. I know if I alter the SQL a little I can get it more or less to work for one month.
So I’ve altered the code to loop for the next 6 months but it only returns 1 result
Here’s my code:
for ($x=1; $x<=6; $x++) {
#echo "Month is: $x <br>";
$date = new DateTime("$x months");
$date->modify("-" . ($date->format('j')-1) . " days");
#echo $date->format('j, m Y');
$month = $date->format('m');
$year = $date->format('Y');
echo 'Month= '.$month .' Year= '.$year.' <br>'; #debug
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM upKeep_postmeta
WHERE meta_key LIKE %s
AND meta_value LIKE %s
",
'dates_%_available_dates', // meta_name: $ParentName_$RowNumber_$ChildName
''.$year.''.$month.'%' // meta_value: 20131031 for example
));
// loop through the results
if( $rows ) {
echo '<ul>';
foreach( $rows as $row ) {
// for each result, find the 'repeater row number' and use it to load the sub field!
preg_match('_([0-9]+)_', $row->meta_key, $matches);
$meta_key = 'dates_' . $matches[0] . '_dates'; // $matches[0] contains the row number!
?>
<li><a href="<?php get_permalink( $row->post_id ); ?>"><?php echo get_the_title( $row->post_id ); ?></a></li>
<?php
}
echo '</ul>';
}
}
I think I’m being daft as I believe the above “should” work. Any help is much appreciated!
Hi,
Could you not add a count to the loop and then start from greater than 1?
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.