Hi @gleenk it looks like you’ll have to retrieve the WP_Post IDs first and next perform an WP_Query or get_posts to order this stuff properly.
Have a look at the following post “Order Post Objects by menu_order”. The Post Object and the Relationship field both return an array of WP_Post objects, so this solution should be possible for you to use.
In your $args you’ll use the following to order by title 'orderby' => 'title'
Please let me know if this works for you…


Hi @squrler
Yes. Please read this documentation article:
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/

Hi @aaronrobb
Yes, this is completely possible. The question is, are you sure that you want to store this kind of information on each post. By doing so, if the user was to update their address, you would have incorrect data all over the place.
It may be smarter to use a user_field to relate the user to the post, then in the template load the address data from the related user.
Is this a possibility?

Hi @digisavvy
So just to clarify, changing the page template correctly triggers the AJA function to load in the new field group, however, it doesn’t hide the origional field group?
A few questions.
Can you post some screenshots of your fiedl groups showing the location rules?
Are you registering these field groups via PHP?
Can you check your console log for any JS errors during hte page load / AJA call?
Thanks
E

Hi @alexgold05
I can see at the top of your code that if the $post_id != ‘new_listing’, you return the $post_id.
This return will stop any further code from working!
Perhaps you need to change your code to look more like this:
<?php
global $current_user;
// check if this is to be a new post
if( $post_id == 'new_listing' )
{
// Create a new post
$post = array(
'post_status' => get_field('default_listing_submission_status','option') ,
'post_title' => $_POST["fields"]['field_522f30035c85b'],
'post_content' => $_POST["fields"]['field_5230848453094'],
'post_type' => 'listing' ,
);
$post_id = wp_insert_post( $post );
}
return $post_id;
?>
I have taken the liberty of removing the update_post functionality as I don’t see how it does anything useful for the above code.
Thanks
E

Currently, there is no filter for the wp_list_categories args within the taxonomy field.
You can edit the core/fields/taxonomy field to add on in, however this may be removed after updating.
I’ll add this to the to-do and add it into the core.
Cheers
E

Hi @Cornholio
A few things. I don’t believe you need to use LIKE as per the meta compare.
The true / false field saves either ‘0’ or ‘1’ for the value, so this compare should simply be ‘=’
As for the numberposts, try changing this to posts_per_page
Good luck
E

Hi @Bassscape
Great work o the query!
Cheers
E

Hi @roflman79
Sure, you can use the following filter to modify the query args!
http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/
Thanks
E

Hi @dreamzsiva
You have 2 options:
1. Leave the HTML as is, inspect it in firebug and then use CSS to alter teh design using floats / widths
2. Use jQuery to pull out the field divs and then place them into placeholders of your own markup
Good luck!
Cheers
E

Hi @cyberwani
If you are using the relationship field, you will be happy to know there is a WP filter available to modify the query args.
You could use the current $post_ID parameter to modify the question to only load posts which have a parent of $post_ID
The filter is documented here:
http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/

Hi @JAVOB
I suspect the issue is due to the way that ACF instantiates the WP tinymce. Due to the requirements of the repeater and flexible content field, the WYSIWYG field must be duplicate-able at run time, which the default WP WYSIWYG does not offer.
I have a feeling that if install and use the WP WYSIWYG field (add-on) your shortcode button will work as expected. If not, the issue most likely lies within the shortcode plugin as it expects only 1 wysiwyg on the page.
Try out the add-on but be aware it won’t work within a repeater / flexible content field.
Thanks
E
Quick update: While the class acf-conditional_logic-hide that the tabs need to be hidden still disappears on save, toggling any other field in the ACF block triggers the script and the acf-conditional_logic-hide class is reapplied. See screenshots below.
As a workaround for the fact that while the tabs themselves don’t respect my desire to hide them, I’ve set all options inside those tabs to hidden and added an additional ACF that simply says “These options are not available” that is not hidden. This way even if the tabs show up users get an explanatory message and can’t tweak anything.


You can use this code in your functions.php file
// Restrict media library to show only own user files
add_action('pre_get_posts','ml_restrict_media_library');
function ml_restrict_media_library( $wp_query_obj ) {
global $current_user, $pagenow;
if( !is_a( $current_user, 'WP_User') )
return;
if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
return;
if( !current_user_can('delete_pages') )
$wp_query_obj->set('author', $current_user->ID );
return;
}
Here’s your code with my code combined 🙂
<?php
if(get_field('image_slider_illustrations'))
{
echo '<ul class="slider">';
while(has_sub_field('image_slider_illustrations'))
{
$attachment_id = get_sub_field('illustrations_image');
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
$attachmentinfo = get_post( $attachment_id );
$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
echo '<li><img src="' . $image[0] . '" alt="' . $alt . '"/></li> ';
}
echo '</ul>';
}
?>
Just tried that and got the expected result – let me know if you’ve still got no joy
Hi,
Thanks for your reply, i managed to make it work however i have an issue with a few fields.
The create new post form, successfully creates the listing and i’m also grabbing the post title and the post content and the featured image through custom fields. This works.
I have then attempted to modify the action so instead of inserting a new post, he would update it. The edit works but some of the fields are not updating. For example when i modify the post and i attempt to modify the custom field that has been used for the post title, it isn’t updating the post title but just the custom field.
This is part of the code used.
global $current_user;
// check if this is to be a new post
if( $post_id != 'new_listing' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => get_field('default_listing_submission_status','option') ,
'post_title' => $_POST["fields"]['field_522f30035c85b'],
'post_content' => $_POST["fields"]['field_5230848453094'],
'post_type' => 'listing' ,
);
$post_edit = array(
'post_status' => get_field('default_listing_submission_status','option') ,
'post_title' => 'test',
'post_content' => 'test2',
'post_type' => 'listing' ,
);
//add listing
if( $post_id = 'new_listing' ) {
$post_id = wp_insert_post( $post );
} else {
$post_id = wp_update_post( $post_edit );
}
Do you have any idea why the form wouldn’t update the post title or the content ?
Thank you. If needed i can post the whole code but i don’t anything else in the action is interfering with it.
It doesn’t seem to be working. Its using a repeater to add new images for a image slider i have. Is that why its not working? And yes its set up to display image ID now.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$attachment_id = get_sub_field('illustrations_image');
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
$attachmentinfo = get_post( $attachment_id );
$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
?>
<ul class="slider">
<li><img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" /><li>
</ul>
</div>
Thanks for your input Elliot, it led me on to find my solution.
I realised I wasn’t using the LIKE operator for my meta_value query and therefore the wildcard values weren’t be recognised. I changed my query to the following and it now returns posts:
$games_id_array = $wpdb->get_results(
$wpdb->prepare(
"
SELECT *
FROM wppp_postmeta
WHERE meta_key LIKE %s
AND meta_value LIKE %s
",
'contributing_game_creators_%_game_creator_roles',
'%'.$search_value.'%'
)
);
You’ll need to have the image set as Image ID
then use something like:
<?php
$attachment_id = get_sub_field('illustrations_image');
$size = "full"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
$attachmentinfo = get_post( $attachment_id );
$alt = get_post_meta($attachmentinfo->ID, '_wp_attachment_image_alt', true);
?>
<img src="<?php echo $image[0]; ?>" alt="<?php echo $alt; ?>" />
You’ll need to edit it to go in amongst your loop but hopefully you’ll get the jist.
The “§ruleS” was just a spelling mistake in the topic, I did use the original array name in the code.
I did write an own code, but I now used the snippet from the documentation. The exact code is:
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
$choices['Basic']['user'] = 'User';
return $choices;
}
add_filter('acf/location/rule_operators', 'acf_location_rules_operators');
function acf_location_rules_operators( $choices )
{
$choices['<'] = 'is less than';
$choices['>'] = 'is greater than';
return $choices;
}
add_filter('acf/location/rule_values/user', 'acf_location_rules_values_user');
function acf_location_rules_values_user( $choices )
{
$users = get_users();
if( $users )
{
foreach( $users as $user )
{
$choices[ $user->data->ID ] = $user->data->display_name;
}
}
return $choices;
}
add_filter('acf/location/rule_match/user', 'acf_location_rules_match_user', 10, 3);
function acf_location_rules_match_user( $match, $rule, $options )
{
$current_user = wp_get_current_user();
$selected_user = (int) $rule['value'];
if($rule['operator'] == "==")
{
$match = ( $current_user->ID == $selected_user );
}
elseif($rule['operator'] == "!=")
{
$match = ( $current_user->ID != $selected_user );
}
return $match;
}
The code is placed at the very bottom of my theme’s functions.php to ensure that it isn’t executed too early.
In your frontend, you’ll have to count number of elements in the repeater field array. So something like this:
<?php
// pre define the allowed columns
$allowed_classnames = array(
1 => 'full',
2 => 'half',
3 => 'third',
4 => 'fourth',
5 => 'fifth',
);
// get the count on the repeater field
// mabye use get_sub_field() instead of get_field() if it's nested
$number_of_cols = count( get_field( '<repeater>' ) );
// set a default classname
$classname_to_use = $allowed_classnames[1];
// check if the $number_of_cols exist in the predefined classnames
if ( array_key_exists( $number_of_cols , $allowed_classnames ) ) {
// set the classname to be used
$classname_to_use = $allowed_classnames[$number_of_cols];
}
while( has_sub_field( '<repeater>' ) ) : ?>
<div class="<?php echo esc_attr( $classname_to_use ); ?>">
<?php the_sub_field( '<repeater_content>' ); ?>
</div>
<?php endwhile; ?>
Please not that I just briefly tested it on a site I’m working on. You’ll have to replace the '<repeater_content>' and '<repeater>' with your actual field names.

Hi @aaronrobb
Can you post the code you use to output VISA?
Also, can you check the DB wp_postmeta table and find the row for this value and the post_id in question? Is the value stored correctly?
Thanks
E

Hi @Bassscape
Your above query will only find posts (that is if the query works as expected) that have Concept and Design selected as the value.
To allow for a value within the array, you shoudl take a look at the checkbox docs:
http://www.advancedcustomfields.com/resources/field-types/checkbox/
On that page, you will see how to use a LIKE statment in the meta_query to match a value.
I have not yet combined this with a sub field DB search, but it must be possible with SQL.
Good luck mate
Cheers
E

Hi @youngwolf0
Your code looks perfect, so for that great work.
Your next step is to debug the function to find out at what line it is failing.
Firstly, turn on DEBUG MODE in your wp-config.php file and then use a simple script like so to test that your loop is working:
<?php
$user = "user_" . $member->ID;
echo '<pre>';
print_r( $user );
echo '</pre>';
?>
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.