I’ve looked briefly into comparison operators and tried to get the below code to work with no success. New to PHP so be gentle :/
<?php $client_id = get_currentuserinfo($user_ID); if ($client_id == get_field('user_select')) : ?>
<p>Working</p>
<?php else : ?>
<p>Not Working</p>
<?php endif; ?>
Hey Elliot,
Sorry, I simplified that to make it easy to understand (but prob made it more confusing :B ). Here’s my full code:
<?php
$args = array ( 'post_type' => 'school-category');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div>
<?php
/* films is a realtionship ACF field */
$films = get_field('films');
if( $films ): ?>
<div class="image_data">
<?php foreach( $films as $post): ?>
<?php setup_postdata($post); ?>
<?php if ( get_field('running_time') ) :
the_field('running_time');
endif; ?>
<?php if ( get_field('images') ) :
$images = get_field('images'); ?>
<img src="<?php echo $images[0]['url']; ?>" alt="<?php the_title(); ?>">
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
The issue is that the if (get_fields(‘images’)) returns a false, where as all over the rest of the site it returns true. I dumped all the post’s custom fields and could see that images was an empty array, where all the ACF fields returned their values.
Any ideas? Thanks Elliot!
Hi @elliot,
As what you suggested earlier, I gathered up an idea tried to implement my queries in the true_false field and I got carried away that the true_false field is fully modified by me and will not be able to serve its purpose anymore. So I created a custom field type instead 😀 out of it.
This is actually a good experience to me and a new learning for today. I succesfully created a “Top[N] Field Type” as what I called it 😀 and it works perfectly.
Thank you for the advise @elliot, really appreciate it.
Cheers!
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>';
}
}
?>
of course:
2 flexible fields
I want to move one of them
and text formatting disappears
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!
@elliot ,
I tried this -> “Finding the term related to the current post” ,
And I was able to finally!
Thank you!!
Looks like you are using a theme which has the options page add-on. Then you are trying to also install the options page add-on as a plugin.
This is why you receive the error.
You can only have 1 instance of the add-on. Not 2.
Thanks
E
Hi @yojoaquin
Sounds like this is a bit beyond the scope of the ACF plugin.
You may want to look into the p2p plugin (to connect users to post types) and write some custom actions / functions to do the activity you desire.
ACF is just an interface for saving / loading custom field data. You are talking about a very custom functional experience which will need to be coded by hand.
Thanks
E
Hi @JAVOB
Thanks for the feedback.
Just 1 question. Can you first click into the ACF WYSIWYG field and type a few characters, then click the shortcode button.
Does the shortcode appear in the correct WYSIWYG when it is correctly focused?
Hi @matu
Sorry, I don’t understand your question.
Please be descriptive.
Thanks
E
Hi @bissy
Thanks for the clarification. So you are looking at a post (single.php) and trying to load the color of the connected category?
This is covered in the following tutorial:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
You will find an example showing how to get the connect term data too
Thanks
E
Hi @ghuigjvyt
Many questions:
1. another field called page appears (text field) – how does this relate to your question?
2. Is your question regarding the backend or frontend?
3. You have tried get_field_object
– where? with what code? What do you mean “it didn’t work?”
Perhaps you could read over your question from someone elses shoes and re-write it so it is clear to understand.
Thanks
E
It was a good question which caused me to do a double take, but alas, the field names are unique. The field titles are the same, but that shouldn’t matter right? Here’s the screen shot you requested.
Hi @jarvis
In SQL, you can only sort results based on 1 value in the row. So the concept of sorting a post based on multiple date values doesn’t work.
Are you actually trying to do this:
Sort the posts based on the earliest date found in the repeater?
Clarification would be great
Thanks
E
Hi @elliot !
I use code below, I want to use the_field(‘color’) in “Edit Category”.
<span class="categorys font-s" style="background-color:<?php the_field('color'); ?>"><?php the_category(' ') ?></span>
It’s in single.php and index.php , and other fields are working fine.
Hi @pjeaje
Thanks for the feature request. At this point, I don’t wish to add this into the core as it would cause many issues across the many installs of ACF.
Perhaps I can write the code and add it as a tutorial for those who wish for all images to be removed via the ACF field.
Thanks
E
Hi @bissy
So you are having issues loading the data?
Have you read this guide:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
What code are you currently using? On what template file?
Please remember that this is a support forum, not a free development service.
Thanks I never forgot, I was just asking as i didn’t know what the code did.
I would appreciate it if you did not create duplicate threads.
This is NOT a duplicate thread. This is a feature request. My other post was asking if it was possible… there’s a big difference in the purpose of the 2 threads.
If someone on this forum asks if a feature is possible and finds out it isn’t, then surely they have the right to then post a feature request (in the correct forum).
So, in fact you haven’t answered this question, that is, As a feature, would you consider adding it in your code. 🙂
Thanks.
Hi @elliot,
Thanks for the suggestion, but I don’t know where to put my queries. I checked on the core->field->true_false codes but I am not certain where to put the conditions.
Could you help me out what files to edit or what folder should I go to? I haven’t tried creating a new field type for acf though.
Thanks
Hi @dashawk
Thanks for the screenshot. I understand the question now.
This is far to custom to include into the core im afraid. That said, it would be possible for you to write some custom code to do this for you.
I would add a function to the wp_head action which would append some jquery to the page. You could query the DB for the amount of posts with this checkbox value (see docs for querying), then depending on the value, you could generate some jQuery to either remove / hide or disable the checkbox field.
All up, it should only take 30 minutes or so.
Good luck
Thanks
E
Hi @seehowtwo
potentially, yes, the issue is caused by un-escaped quote marks.
I have not experienced this issue before, so it could be server specific.
Easiest way to get the field back working is remove the quote marks and update the corresponding string count
Hi elliot,
Thanks for the quick reply, I am uploading the image of what my idea is all about.
Thanks
Hi @pjeaje
Thanks for your feedback, however this is outside the scope of the ACF plugin.
Your topic here:
http://support.advancedcustomfields.com/forums/topic/can-i-delete-images-permanently/
already covers the question “how to delete images permanently”.
I would appreciate it if you did not create duplicate threads.
Thanks
E
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.