Thank you SO much! This is what I ended up with…
<div>
<?php $associations = get_field('associations');
if( $associations ): ?>
<?php foreach( $associations as $association): ?>
<?php
$photo = get_field('investment_logo', $association->ID); ?>
<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" />
</a>
<?php endforeach; ?>
<?php endif; ?>
<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
<?php the_title(); ?></a>
<em><?php the_field('publication_source'); ?></em>
<span><?php $date = get_field('publication_date'); echo date('F d, Y', datepicker_to_unix($date )); ?></span>
</div>
Really appreciate your quick response! Thank you!!
I tried already what you write, and then the HTML result is:
<textarea id="acf-field-text-year" class="year_n_text" name="f"></textarea>
<textarea id="acf-field-vita-year" class="year_n_text" name="f"></textarea>
Hi @elliot.
Sorry my bad.
That was some older code. I did in fact use a img tag but to no success.
<?php $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<li>
<a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>">
<div class="subdivision">
<?php
if (get_field('sub_division_image')){ ?>
<img src="<?php the_field('sub_division_image'); ?>" alt="<?php echo $pageChild->post_title; ?>" />
<?php } else {
echo "Hello world";
} ?>
</div>
<p><?php echo $pageChild->post_title; ?></p>
</a>
</li>
<?php endforeach; endif; ?>
Any thoughts?
Cheers,
GM
Hi @wells5609
Thanks mate. Yes, WP 3.6 still works with .live, but in ACF v4.2.0 I have changed all .live to .on!
Thanks
E
Hi @marcelolz
Are you creating a premium theme/plugin for distribution? If so, the above resource will explain how you can do thi.
If you are creating a website for a client, this is not necessary at all.
Hi @Koli14
Yes, it is the name which is used to post data.
As mentioned above, if you want to send 2 textarea’s in the same name, you will need to use square brackets to tell the browser it is an array of information.
For example, you want the output to be:
<textarea name="fields[field_123][textarea_1]"></textarea>
<textarea name="fields[field_123][textarea_2]"></textarea>
Thanks for the screenshots.
The code you want to use will look something like this:
<div>
<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
<em><?php the_field('publication_source'); ?></em>
<span><?php $date = get_field('publication_date'); echo date('F d, Y', datepicker_to_unix($date )); ?></span>
<?php
// 1. Get all the relationship values
$associations = get_field('associations');
// 2. Make sure a value exists
if( $associations ): ?>
<?php
// 3. loop through relatinoship values
foreach( $associations as $association): ?>
<?php // 4. Load the image field from the association ?>
<img src="<?php echo get_field('investment_logo', $association->ID); ?>" />
<?php endforeach; ?>
<?php endif; ?>
</div>
Please note this is an example and not the final Markup you will need.
Thanks
E
If the value is saved as an array, you can treat the field the same as a relationship field. This means, you can follow this tutorial for your post_object field:
http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/
Quite simply, a disabled input is never posted to the save function.
Maybe you should use the readonly attribute instead!
Easy
Cheers
E
Hi @rdck
Sorry, I completely missed the issue!
The issue is that you are using a while loop which will never end!
You should be using a foreach!
Hi!
I honestly think you’ll be better of creating this yourself..
simply do an update_post_meta on the wp_save_post hook.. something like this (not tested):
function save_book_meta($post_id) {
$slug = 'book'; //CHANGE THIS TO THE SLUG OF YOUR POST TYPE
/* check whether anything should be done */
$_POST += array("{$slug}_edit_nonce" => '');
if ( $slug != $_POST['post_type'] ) {
return;
}
if ( !current_user_can( 'edit_post', $post_id ) ) {
return;
}
$current_user = wp_get_current_user();
update_post_meta($post_id, 'latest_author', $current_user-> display_name);
}
add_action( 'save_post', 'save_book_meta');
This will save the current users display name as a custom field called “latest_author”.
Thanks! Using that tutorial, I came up with this quick and dirty custom rule:
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
$choices['Post']['post_status'] = 'Post Status';
return $choices;
}
add_filter('acf/location/rule_values/post_status', 'acf_location_rules_values_post_status');
function acf_location_rules_values_post_status( $choices )
{
$post_status = array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash');
$num_status = count($post_status);
for ($index = 0; $index < $num_status; $index++)
{
$choices[$post_status[$index]] = $post_status[$index];
}
return $choices;
}
add_filter('acf/location/rule_match/post_status', 'acf_location_rules_match_post_status', 10, 3);
function acf_location_rules_match_post_status( $match, $rule, $options )
{
$this_post_status = get_post_status($options[post_id]));
$selected_post_status = $rule['value'];
if($rule['operator'] == "==")
{
$match = ( $this_post_status == $selected_post_status );
}
elseif($rule['operator'] == "!=")
{
$match = ( $this_post_status != $selected_post_status );
}
return $match;
}
Ideally, you’d wouldn’t have to hard-code the array of statuses (in case they change or custom ones have been created), but quick googling didn’t turn up a WordPress construct that returns an array of defined post statuses.
Yes, i checked the generated HTML source, and played with a few versions (with brackets, in quotes…), i’m not expert in PHP…
It still not working, maybe i asked the question wrong.
So the name of the textarea is how ACF knows which field to save (not the ID or class)? So if i want two textarea, they need to have different names.
Now the working field has a name: $field[‘name’] which generates: fields[field_51fbdeb7f1609].
What should i add as a name to the second textarea, and how can i get the value of it?
I can get the value of the field with the $field[‘value’], but it’s just the value of the textare with the name: $field[‘name’].
Uhhh, maybe it’s a bit too complicated for me…
Yes, I am aware that I need to put the relationship code within my loop but I don’t know what the code should be. Every time I tried adding it, I got a php error. I’m confused because I’m already querying multiple different posts on the page (unlike the documentation which shows an example of querying for a single template file).
Please see the screenshots for what I’m working with. I know this is slightly complicated but I’m sure folks would want to know how to do this as well.
I want to query the image somewhere between this div.
<div>
<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
<em><?php the_field('publication_source'); ?></em>
<span><?php $date = get_field('publication_date');
echo date('F d, Y', datepicker_to_unix($date )); ?></span>
</div>
Really appreciate your help! Thank you!!
Since I’m using it for the post type “course”, I changed the post_type=post into post_type=course.
However, the count still doesn’t work (it still counts everything).
Also, the 1st part of your code (that you last posted) doesn’t work (to show only the authors content) – while an earlier example of you did work – so I used the code below for the first part and added the “Fix post counts” count only.
What I’m currently using (working code).
// So authors can only see their own content (e.g. courses etc)
function posts_for_current_author($query) {
if( !$query->is_admin )
return $query;
$screen = get_current_screen();
if ($screen->base === 'post')
return $query;
if( !current_user_can( 'activate_plugins' ) ) {
global $user_ID;
$query->set('author', $user_ID );
}
return $query;
}
add_filter('pre_get_posts', 'posts_for_current_author');
I haven’t been able to get the count correct, see http://d.pr/i/Ijhs.
Hi all,
I’m new using this plugin and I have the same issue here.
I have this code:
<?php $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY menu_order", 'OBJECT'); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<li>
<a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>">
<div class="subdivision">
<?php
if (get_field('sub_division_image')){ ?>
<?php the_field('sub_division_image'); ?>
<?php } else {
echo "Hello world";
} ?>
</div>
<p><?php echo $pageChild->post_title; ?></p>
</a>
</li>
<?php endforeach; endif; ?>
But there is no way to get the image to show up on my page. If I use the plugin as a custom text field it will work just fine. Any help would be very appreciated!
Thanks.
GM
Thanks for the reply @elliot, however, adding the endif; doesn’t solve it. It still is spitting out the word ‘test’ infinitely and crashing the site, rather than what is to be expected.
<?php $courses = get_posts(array(
'meta_query' => array(
array(
'key' => 'short_course', // name of custom field
'value' => '"yes"', // matches exaclty "yes", not just yes. This prevents a match for "acquired"
'compare' => 'LIKE'
)
)
));
if ( $courses ) : while ( $courses ) : ?>
test
<?php endwhile; endif; ?>
Hi @markgdyr
Thanks for the bug report.
Looking at the file, the line in question is:
$o['name'] = end(explode('/', $o['url']));
Seems like WP’s new strict standards has an issue with the ‘/’ as a parameter?
That’s pretty strange…
Do you have debug mode on or off?
Sorry for speaking to myself. I have figured it out. I have done the following. Thanks again for your help @elliot
<script type="text/javascript">
jQuery(document).on('acf/setup_fields',function(e){
//alert('test');
jQuery( "#dialog" ).dialog();
});
</script>
Hi @elliot,
thank you for your answer. I have already read this article, but I don’t reaklly understand it. Do I have to create the acfg/setup_fields action in my wordpress functions.php or directly into my HTML in the create_field function() ?
My create_field function looks like this now. But it doesn’t work š
function create_field( $field )
{
// defaults?
/*
$field = array_merge($this->defaults, $field);
*/
// perhaps use $field['preview_size'] to alter the markup?
// create Field HTML
?>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script>
$(document).live('acf/setup_fields', function(e, div){
// div is the element with new html.
// on first load, this is the $('#poststuff')
// on adding a repeater row, this is the tr
$(div).find('.class').each(function(){
$(this).doIt();
});
});
function doIt() {
alert("Hello World!");
}
</script>
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<?php
}
Cheers,
javanese
On the off chance that someone else may be looking for this, here’s my solution.
It checks whether the field exists, then outputs 10 RSS feed items including title and full content.
<?php $blogfeed = get_post_meta($post->ID, āblog_feedā, true);
if($blogfeed) : ?>
<?php
include_once(ABSPATH.WPINC.ā/rss.phpā); // path to include script
$feed = fetch_rss($blogfeed); // specify feed url
$items = array_slice($feed->items, 0, 10); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>
<div class=āfeed-itemā>
<h4>ā target=ā_blankā><?php echo $item['title']; ?></h4>
<p><?php echo $item['atom_content']; ?></p>
</div>
<?php endforeach; ?>
<?php endif; ?>
Turns out it pulls up the feed just as I entered above, but it doesn’t quite work:
– If I hard-code a URL, it pulls up the feed items info
– but when I use ACF, it prints the feed URL and then gives an error:
Warning: array_slice() expects parameter 1 to be array, null given in myfile.php
It’s like it outputs the feed URL differently than a hardcoded one. get_field didn’t do anything at all.
What’s the proper way to include feed URL in there so it would be processed as it should?
Hi @javanese
It is important to place your jQuery code within the acf/setup_fields action.
This ensures that all HTML is ready for jQuery
You can read more in this guide:
http://www.advancedcustomfields.com/resources/getting-started/adding-custom-javascript-jquery-for-fields/
Hi @gato_gordo
Thanks for the request.
Yes, it is quite easy to create a custom location rule. You can follow this guide to do so:
http://www.advancedcustomfields.com/resources/tutorials/custom-location-rules/
I’ll also add this request to the to-do as I would like to see it in the core over the next coming versions
Thanks
E
Hi @rdck
Does your code contains an endif
?
Perhaps it is not the query but a syntax error on the page?
Can you turn on DEBUG MODE in your wp-config.php
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.