Hi @elliot
I still don’t really follow how that will work. In the example, that requires you put in a key value of ‘Melbourne’. That is great if you only have one value called ‘Melbourne’, but I have 30 different artists.
How can I tell which artist page I am currently on before I show the value for that particular artist without setting up 30 different templates?
Does that make sense?
If I am on the Metallica page, I ONLY want to show Metallica releases. With 30 artists, do I need to set up 30 templates to call the specific artist value on each one?
Hi Elliot,
Thanks for your reply, I know it isn’t a ‘regular’ wordpress query. I’m just trying to get it working like one.
I got my following code working with a custom query_var called albums: Pastebin
And I can use the url: http://mydomain.local/pagename/?albums=2
The last thing I want to achieve is a rewrite rule for the query var, but somehow that isn’t working yet. I would like an url like this: http://mydomain.local/pagename/page/2/
/* Photo albums pagination parameter */
function add_albums_query_var(){
global $wp;
$wp->add_query_var('albums');
}
/* Rewrite rules albums pagination */
function add_albums_rewrite_rule() {
add_rewrite_rule('^/page/([0-9]+)/?$', 'index.php?p=25&albums=$matches[1]', 'top');
}
add_filter('init', 'add_albums_query_var');
add_action('init', 'add_albums_rewrite_rule');
25 is the page id where the repeater field is looped.
Any idea why this isn’t working?
Thanks a lot!
Do you mind giving me any tips on formatting and code structure? I am kinda new to PHP and although this works I am not confident.
One other question I have is, can you recommend a way to approach a UI that would let a user jump to points on the page that are grouped into the same month? Back story is each repeater will have a name and date and now, since I can sort the list by date I was hoping to make it easier for the user to jump to the content for August.
<!-- repeater -->
<?php
$repeater = get_field('race_event');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['race_date'];
}
array_multisort( $column_id, SORT_ASC, $repeater );
foreach( $repeater as $row ) :
{
echo '<li>' . $row['race_name'] . '</li>';
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
echo '<li>' . $date->format('m-d-Y') . '</li>';
}
endforeach;
?>
<!-- /repeater -->
Hi @hungrysquirrel,
It is possible to sort by date with the above method.
Let me know if you have any problems š
Cheers
Thank you for your quick response.
I was trying to emulate something like on this site:
http://thereason.us/
using a combination of the gallery add-on and jquery masonry.
Please let me know if you have any recommendations.
PS – I love your plug ins!
Ah!
Also, check that you donāt have any āpre_get_postā filters that are modifying the args
That put me int he right direction. none of the other orderby arguments seem to work.
I changed up the query to:
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => '-1',
'meta_key' => 'date_received',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
remove_all_filters('posts_orderby');
$query = new WP_query($args);
And that fixed it. If this was in the documentation, my apologies for not seeing it. Either way, I’m good to go and thank you for your help.
Hi @NWTD
Try removing ACF from the equation by changing your ‘orderby’ value to ‘title’. Do the posts order by title? Perhaps also try ‘rand’.
If these work, perhaps try 'orderby' => 'meta_value'
(without the ‘_num’)
Also, check that you don’t have any ‘pre_get_post’ filters that are modifying the args
Hi @bgomski
Can you please edit the above to clearly describe the issue. There are many parts to your query that are confusing:
1. I have custom field group (repeater) on page A
Is this a field, or a field group?
2. one of those fields is a āTrue / Falseā box.
Is this a sub field or normal field?
3. What is ‘all of the content from that field group post’
4. What is page B?
5. How do you access page A and page B?
6. How does page B know of page A?
Thanks
E
Hi @andrefelipe,
Thankyou for your request! It has been added to a report for Elliots attention
Have a nice day
Thanks for the response @elliot.
My apologies for not clearing this up sooner. My query displays the posts. They’re just not ordered by the meta_key defined in the query. The meta_key is a datepicker from ACF.
Here’s how the query looks on the front end: http://imgur.com/ANmN8ft
Notice how the dates are not in order? The posts are in order by the post date, not the date set forth by the advanced custom field.
I hope that helps to clear up any confusion.
Hi @ayottepl
Here is a good article to read:
http://www.advancedcustomfields.com/resources/faq/losing-data-save/
Thanks
E
Hi @NWTD
Thanks for the screenshot. Can you confirm that this setting has never been changed and that all posts have saved in the correct format?
Perhaps you have another issue in your WP_Query args. The best way to find the issue is to remove parts from the args one at a time until the issue resolves itself.
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => -1,
'meta_key' => 'date_received',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$query = new WP_query($args);
var_dump( $query->have_posts() );
Perhaps remove the orderby and order? perhaps remove the meta_key also?
Thanks
E
Hi @Sarah
Perhaps you could hook into the update_value filter and escape all values before they are saved to the DB?
The filter in question can be read about here:
http://www.advancedcustomfields.com/resources/filters/acfupdate_value/
Thanks
E
Hi @Twansparant
The above code is not a WP_Query, therefore the above code would not work,
Thanks
E
Hi @matoma16
Edit your repeater field and find the image sub field. The image sub field will show an option for ‘required’. Set this to ‘Yes’ and your image fiedl will be required.
Thanks
E
Hi @Ionut Staicu
Yes, multiple field groups can’t be joined by tabs (yet).
Perhaps in the future, I can add this in, but the WP metaboxes make this idea quite complicated
Thanks
E
@Sarah
i added it from a custom plugin like this:
add_action( 'wp_enqueue_scripts', 'my_enqueue_styles_scripts' );
function my_enqueue_styles_scripts() {
wp_enqueue_script( 'acf-custom-validation', plugins_url( 'inc/js/acf-custom-validation.js', __FILE__ ), array( 'acf-input' ) );
}
I am still very interested in finding a solution to this however Elliot, what you stated above went right over my head. It is possible you could consolidate it into a working technique…
Any help is greatly appreciated.
Trying to add some custom .js validation (as per the above) on a front end form, but can’t get it to work. Where should this code go?
I’ve tried adding inline on the form page, and also as a separate script via wp_enqueue_scripts
action, but no joy?
Thanks!
Thanks. I have done some initial testing.
If one has a front end form with text field, a malicious user could potentially input <script>alert('You've been hacked');</script>
and if echo get_field
or the_field
is used to output that field, the script will then run.
As far as I understand it, one would therefore use echo esc_html (get_field(..));
to escape the data on output (or esc_attr, esc_url, etc as appropriate)
I think this needs highlighting right at the top of your Front End form ‘how-to’!
What I have yet to establish is whether any additional sanitization needs to be done before the data is input to the database. According to http://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows, $wpdb->update takes raw input values (they should not be SQL escaped) – so perhaps that’s enough?
The only thing that bothers me is that potentially one could then still end up with malicious js script in the db – maybe the answer is to use esc_html on input to db as well as output.
Any further thoughts welcome…
Hi Elliot,
Would it be possible to use the builtin WordPress $paged function instead?
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
And after the loop call the default pagination functions like this?
next_posts_link();
previous_posts_link();
An working example would be very welcome for this indeed.
Thanks a lot!
Thanks for quick reply! Tried deactivating all plugins and didn’t work. However did a clean install of WordPress + same theme and it worked ok, so the problem must be on my end :/
Not sure if this is also similar:-
http://stackoverflow.com/questions/17648825/get-variable-out-of-anonymous-javascript-function
Can you perhaps make the ACF function ‘Global’ as per something similar here:-
First, Awesome work on ACF!
Just a Note: It looks like metaboxes aren’t honoring “Screen options” to turn on or off the metabox. While this works when the user clicks “Screen options” to hide a given metabox (jQuery toggles display:none/block), it’s not remembering the user set preferences.
I’ve tracked the line down for you at line #714 in everything_fields.php. It looks like there is no initial style=”display: …” set. This needs to pull the user’s set value or leverage WP’s hidden_meta_boxes filter to know what the initial value is/should be.
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.