Hi @pursuit
Just to clarify, you want to use the wp-admin user page but add a custom search filter to query the data?
Please let me know if this is what you are attempting to do. It seems I don’t quite understand your question yet.
Thanks
E
Hi @jmb
Sorry, I’m quite confused in regards to your last comment.
Can you please create a fresh topic and clearly state the issue and how to replicate it?
Thanks
E
To bulk update this value, I would create a new page template where you can write and run some custom code.
This template would use the WP_Query / get_posts function to query the DB for all the posts you want to update.
Then, loop through all the posts and for each post, load the ACF value (get_field()), and then use the wp_update_post function to set the post_content with the ACF value.
Hope that helps.
Thanks
E
And here is my single.php:
<?php get_header(); ?>
</header>
<div id="content" class="row artist single-col">
<?php the_post(); ?>
<article <?php if(function_exists("live_edit")){live_edit('post_title,short_blurb,photo, instrument_or_service, facebook_link, twitter_link, email_address, website_address, soundcloud_link, bandcamp_link, itunes_link, youtube_link, vimeo_link, audio_track_or_playlist, single_bandcamp_audio_tracks, youtube_videos, vimeo_videos, another_photo, full_bio'); }?>>
<?php
$attachment_id = get_field('photo');
$size = "medium"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<img class="artist alignleft" src="<?php echo $image[0]; ?>" />
<h1 class="h2"><?php the_title(); ?></h1>
<?php
$tags = get_field('instrument_or_service');
if( $tags ):
echo '<p>';
foreach( $tags as $tag):
setup_postdata($tag);
echo '<a href="/' . $tag->taxonomy . '/' . $tag->slug . '">' . $tag->name . '</a>, ';
endforeach;
endif; wp_reset_postdata();
?>
</p>
<p><?php the_field('short_blurb'); ?></p>
<div class="social-links">
<?php if( get_field('facebook_link') ) { ?>
<a title="Facebook" href="<?php the_field('facebook_link'); ?>" class="facebook-link">Facebook</a>
<?php } ?>
<?php if( get_field('twitter_link') ) { ?>
<a title="Twitter" href="<?php the_field('twitter_link'); ?>" class="twitter">Twitter</a>
<?php } ?>
<?php if( get_field('email_address') ) { ?>
<a title="Email" href="mailto:<?php the_field('email_address'); ?>" class="email">Email</a>
<?php } ?>
<?php if( get_field('website_address') ) { ?>
<a title="Website" href="<?php the_field('website_address'); ?>" class="website">Website</a>
<?php } ?>
<?php if( get_field('soundcloud_link') ) { ?>
<a title="Soundcloud" href="<?php the_field('soundcloud_link'); ?>" class="soundcloud">Soundcloud</a>
<?php } ?>
<?php if( get_field('bandcamp_link') ) { ?>
<a title="Bandcamp" href="<?php the_field('bandcamp_link'); ?>" class="bandcamp">Bandcamp</a>
<?php } ?>
<?php if( get_field('itunes_link') ) { ?>
<a title="iTunes" href="<?php the_field('itunes_link'); ?>" class="itunes">iTunes</a>
<?php } ?>
<?php if( get_field('youtube_link') ) { ?>
<a title="YouTube" href="<?php the_field('youtube_link'); ?>" class="youtube">YouTube</a>
<?php } ?>
<?php if( get_field('vimeo_link') ) { ?>
<a title="Vimeo" href="<?php the_field('vimeo_link'); ?>" class="vimeo">Vimeo</a>
<?php } ?>
</div>
<div class="controls">
<a href="#listen">Listen</a>
<a href="#watch">Watch</a>
<a href="#read">Read</a>
</div>
<section id="listen">
<h2>Listen</h2>
<div class="row">
<?php if( get_field('audio_track_or_playlist') ): ?>
<?php while( has_sub_field('audio_track_or_playlist') ): ?>
<?php the_sub_field('track_id_number_soundcloud'); ?>
<?php endwhile; ?>
<?php endif; ?>
<?php if( get_field('single_bandcamp_audio_tracks') ): ?>
<?php while( has_sub_field('single_bandcamp_audio_tracks') ): ?>
<?php the_sub_field('track_id_number_bandcamp'); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
<h2>Releases/Appears On</h2>
<section class="thumb-list">
<div>
<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
<p>
<a href="">Release Name</a><br />
<em>Artist Name</em><br />
<span class="date">the date</span>
</p> </div>
<div>
<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
<p>
<a href="">Release Name</a><br />
<em>Artist Name</em><br />
<span class="date">the date</span>
</p>
</div>
<div>
<a class="thumb" href="<?php the_permalink(); ?>"><img src="http://placehold.it/150/150"></a>
<p>
<a href="">Release Name</a><br />
<em>Artist Name</em><br />
<span class="date">the date</span>
</p>
</div>
</section>
</section>
<section id="watch">
<h2>Watch</h2>
<?php if( get_field('youtube_videos') ): ?>
<?php while( has_sub_field('youtube_videos') ): ?>
<div class="video">
<?php $code = get_sub_field('video_link'); ?>
<?php echo do_shortcode('[youtube id="'.$code.'"]'); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php if( get_field('vimeo_videos') ): ?>
<?php while( has_sub_field('vimeo_videos') ): ?>
<div class="video">
<?php $code = get_sub_field('video_link'); ?>
<?php echo do_shortcode('[vimeo id="'.$code.'"]'); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</section>
<section id="read">
<h2>Read</h2>
<?php
if( get_field('another_photo') ){
$attachment_id = get_field('another_photo');
$size = "medium"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
?>
<img class="artist alignleft" src="<?php echo $image[0]; ?>" />
<?php } ?>
<?php the_field('full_bio'); ?>
</section>
</article>
<?php get_footer(); ?>
Hi @elliot,
Before I forget to tell you: I have found the solution for my problem, which was actually rather simple 🙂 Found it by looking closely at your documentation.
It is possible to update all fields on all pages using the options page! I simply had to add the attribute ‘option’ to the fields themselves! Like so:
<?php the_field('opslogan', 'option'); ?>
Works like a charm now 🙂
The only thing I couldn’t find in the docs is how to use this option attribute in a shortcodes field. I’ve tried it like this, but this is not working:
<img src="[acf field="usp1" "option" post_id="43"]" alt="usp" />
Also options without quotes, or after a comma doesn’t seem to work.
Do you have any tips on getting shortcode fields to work with the options pages?
Thx in advance!
Hi @elliot,
Thank you, again, for continuing to work with me on this issue.
I have read the threads at the URLs you posted. It seems the developers involved in the threads are trying to accomplish something different than what I am trying to do. I gather that they are trying to add a custom column to the users table in the Dashboard so that they can sort on the custom column. I, on the other hand, am trying to filter the entries in the table down to those who match the criteria I submit to the search form. I am thinking that sorting on a custom column will be a poor solution once the number of users gets large, i.e. 100, 500, 1000, 1000000. I want my administrators to only have to scan through the few user records that match their search criteria.
Did I misunderstand the solutions proposed in the threads at the URLs you posted?
Lastly, I should let you know that I have posted a more general question about this issue to the WP support forum. You can find my post at the URL below. My post has not yet received any replies.
http://wordpress.org/support/topic/querying-the-wp_usermeta-table?replies=1
Thank you.
I now remeber why this behaviour felt so strange:
It happens when I change the value (ie select a different…) option button:
I have a default option button loded when I select the tab, and when I change it for another option, it keeps the newly selected option, but immediately bounces back to the first tab…! Obviously there is no other way of selecting another option than to click it with th emouse (tabbing selects the next field…), and that prompts the “tab-bouncing”….!
Hi @elliot,
And thanks for your reply!
Yes, I guess this is what might be happening.
So the correct thing to do would be use the mouse / TAB ONLY to select skip from one field / tab to another…
I understand the logic for hitting enter / saving, but I must be a mistake clients / end-users often make too !!
I’ll just have to make sure that the client is well aware of this, as it seems more intuitive to ‘enter’ than anything else …
Anyway, many thanks again for your prompt reply & clear answer.
Rgds,
JMB
Hi @elliot,
Many thanks for your reply.
I’ll tweak this function/hook to see if I can understand the way it works.
I do have a question , though:
the “field” I need to change is the post_name, which obviously goes into the WP_POST Table of the DB. If I understand correctly, this should be the $value from the hook function ? & the aggregated ‘data’ (ie. something like get_field(‘firstname’).” “.get_field(‘lastname’)) should be the $field parameter of the function ? & How do I get the $post_id ?
Sorry if I sound thick, lol !
I’d like to var_dump() either the WP_post post before it gets recorded to see what the variable / object hold . When & how should I do this ?
Many thanks again for your help.
OK. I see the problem. Unless WP were to update the term_relationships table so it could distinguish object_ids as belonging to a user or a post, the potential for conflict is unavoidable.
My main goal is to run taxonomy queries for a user. It would work about as well for me to run meta queries for a user except that ACF stores the taxonomy terms in a serialized array in the user_meta table. I don’t know of a reliable way to run a meta query that looks for a value in a serialized array. If ACF stored taxonomy term ids each as a separate user_meta fields, then I could effectively run a user meta query. I realize that would be a big shift for ACF and I don’t expect you to take it on.
I’ll likely solve this by creating my own user-taxonomy field. Since I know in my particular instance I won’t have term taxonomies shared between posts and users, I’ll probably store the taxonomy terms as such but I may explore storing them as separate meta fields instead. I very much appreciate that ACF is built with enough flexibility to make it straightforward for me to create my own field for this.
Hi @smohlke
Thanks again for the above code.
After some reviewing, I’m not sure this can be added into the core due to a potential data conflict issue.
There is a case when taxonomy terms will be saved to object 5. Object 5 can be both a post AND a user. Although this situation is unlikely, it make occur in a large scale web app when importing many entries where the data is connected with taxonomies in a complicated way.
For example, a user may be connected to a ‘company’ and also a page may be connected to a ‘company’ – in this case, ‘company’ is a taxonomy term.
When editing the page or the user, the term relationship data would not be unique and would override each other.
I think for now, I won’t add this in but will leave this for a future day when I can find a better solution.
Thanks
E
Looking in the docs I found to use this:
<?php
function my_acf_update_value( $value, $post_id, $field )
{
$value = "Custom value";
// do something else to the $post object via the $post_id
return $value;
}
// acf/update_value - filter for every field
add_filter('acf/update_value', 'my_acf_load_field', 10, 3);
// acf/update_value/type={$field_type} - filter for a specific field based on it's type
add_filter('acf/update_value/type=select', 'my_acf_load_field', 10, 3);
// acf/update_value/name={$field_name} - filter for a specific field based on it's name
add_filter('acf/update_value/name=my_select', 'my_acf_load_field', 10, 3);
// acf/update_value/key={$field_key} - filter for a specific field based on it's name
add_filter('acf/update_value/key=field_508a263b40457', 'my_acf_load_field', 10, 3);
?>
However, adding just that to my functions.php causes a bunch of errors when trying to publish a post:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'heading2' not found or invalid function name in /home/movies9/public_html/msv6/wp-includes/plugin.php on line 199
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'heading2' not found or invalid function name in /home/movies9/public_html/msv6/wp-includes/plugin.php on line 199
Warning: Cannot modify header information - headers already sent by (output started at /home/movies9/public_html/msv6/wp-includes/plugin.php:199) in /home/movies9/public_html/msv6/wp-admin/post.php on line 222
Warning: Cannot modify header information - headers already sent by (output started at /home/movies9/public_html/msv6/wp-includes/plugin.php:199) in /home/movies9/public_html/msv6/wp-includes/pluggable.php on line 899
If I just want this to effect the “heading2” custom field. How would I edit it?
Hi @astrixoblix
You will need to populate the meta_query args based on the checkbox value you have. Something like this should work:
<?php
$checkbox_field = get_field( 'checkbox_field', $post->ID );
$args = array(
'post_type' => 'page',
'post__not_in' => array( $post->ID ),
'posts_per_page' => $related_no,
'meta_query' => array(
'relation' => 'OR',
)
);
if( $checkbox_field )
{
foreach( $checkbox_field as $v )
{
$args['meta_query'][] = array(
'key' => 'checkbox_field',
'value' => '"' . $v . '"',
'compare' => 'LIKE'
);
}
}
// test args
echo '<pre>';
print_r($args);
echo '</pre>';
die;
?>
Hope that helps.
Thanks
E
Hi @jmb
When you hit enter, you are ‘saving’ the post, not updating the post.
Saving a post bypasses validation, so when you say that “he form bounces back to the fist tab”, it’s probably the whole page is reloaded and the first tab is shown on page load.
Could this be correct?
Thanks
E
Hi @funkjedi
Nice fix!
Thanks
E
Hi @owenoneill
Can you please disable the plugins:
qa
really-simple-facebook-twitter-share-buttons
opendays
And reload the page?
Thanks
E
Hi @elliot
Yes. i’m getting the values of current post’s checkbox via get_field, and i’m trying to find any pages which have any of current checkbox values.
as i said, i’m trying to create something like ‘related post’ but via ACF checkbox.
i’m not sure how i should dynamically generate the meta_query args array.
i tried this code:
$checkbox_field = get_field( 'checkbox_field', $post->ID );
$args = array(
'post_type' => 'page',
'post__not_in' => array( $post->ID ),
'posts_per_page' => $related_no,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'checkbox_field',
'value' => $checkbox_field ,
'compare' => 'IN'
)
)
);
didn’t worked.
removing ‘relation’ => ‘AND’, adding meta_key does not have any effect on result.
i searched whole google, but didn’t find any solution for my problem. how i should do that :S
Thanks,
A
Hi @elliot,
The WP_User_Query class seems like a good way to search for users, but I currently do not see a way to make use of the class when an administrator searches for users in the Dashboard. If I were writing a separate search tool, the WP_User_Query class seems like it could work. But I want to tap into what WordPress already has in place.
Do you have any suggestions for how I can extend the functionality of WordPress’s existing user search tool?
A link to a pastebin of what I have in mind is below. (The code does not work as I expected it would.)
Hi @elliot!
Firstly thanks for the great plubin & and your support. I’ve scanned the support & saw that you always answer most thoughroughly.
Greta job!
So here I am with my ‘issue”, which I guess looks like what @augusto pointed out :
I have created some tabs which show or not accordind to previous conditions. Theses tabs have some required files, but of course they are not filled in if the tab is not called by the condition…
I wonder if that is the reason why , when I fill in fields in one of these fields & hit ‘return’, the form bounces back to the fist tab (eg. the one that shows first(..) and which has no restriction for showing…?
A bug, an issue, most probabbly a mis-use of fields / tabs from my part ?
Many thanks anyway
Regards,
JMB
Hi @codeview
Thanks for the follow up.
You will need to debug your code line by line to find out why the date is incorrect. You can debug like this:
<?php
/*
* Create PHP DateTime object from Date Piker Value
* The ACF "Workaround" for PHP 5.2 as shown in the docs
*/
$date = get_field('event_enddate'); // $date = 19881123 (23/11/1988)
echo '<pre>';
print_r( $date );
echo '</pre>';
die;
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
echo '<pre>';
print_r( $y );
echo '</pre>';
echo '<pre>';
print_r( $m );
echo '</pre>';
echo '<pre>';
print_r( $d );
echo '</pre>';
die;
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
echo '<pre>';
print_r( $time );
echo '</pre>';
die;
?>
Please note there are 3 sections to this code which print out and die. Once you are happy with the result, just remove that print_r section and allow the next to run.
This should help explain where the issue starts
Thanks
E
Hi @astrixoblix
Just to clarify, you are loading the current checkbox value via get_field, then you want to find all other posts which have exactly the same checkbox values? Or are you finding any posts which have any of the checkbox values ticked?
I think you need to dynamicaly generate the meta_query args array by loop through your checkbox values and appending to the meta_query args array.
Does that help?
Thanks
E
Hi @astrixoblix, it works.
Thank u and @elliot. And I wanna go farther. As the image shown in my first post, I want to show 3 related produces. Now I repeat the code 3 times.
$related_1 =
...
$related_2 =
...
$related_3 =
...
is it stupid? Any better idea?
Here are the codes generated by ACF:
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_releated-products',
'title' => 'Releated Products',
'fields' => array (
array (
'key' => 'field_5296d411901eb',
'label' => '1st related product',
'name' => '1_related_product',
'type' => 'post_object',
'post_type' => array (
0 => 'product',
),
'taxonomy' => array (
0 => 'product_category:213',
),
'allow_null' => 1,
'multiple' => 0,
),
array (
'key' => 'field_5296d53cf9d3e',
'label' => '2nd related product',
'name' => '2_related_product',
'type' => 'post_object',
'post_type' => array (
0 => 'product',
),
'taxonomy' => array (
0 => 'product_category:213',
),
'allow_null' => 1,
'multiple' => 0,
)
...
Alright. That is helpful to know.
I had a follow up question but I think I just answered it for myself. Let me do some additional research and see if I can develop a working solution. I plan on returning to the forum to ask an additional question or to mark this issue as resolved.
You don’t need to modify ACF can just throw this in your functions.php
add_filter('acf/format_value_for_api', 'theme_format_value_for_api');
function theme_format_value_for_api($value) {
return is_string($value) ? __($value) : $value;
}
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.