Hi @codynew
No worries, i should realy find some time to write a tutorial about this, but it is quite easy.
First, you need to render out your filters – I’ll leave this bit to you. The filteres should be clickable links to the same url with an added $_GET param that contains the filter name and filter value eg:
website.com/filter-page/?foo=bar&foo2=bar2
Next, you need to edit the page template and look at the available $_GET params. Use these to modify the $args that you then send to the WP_Query class.
Loop through the query results and then output the HTML.
Easy!
Good luck
Thanks
E
You can use a simple counter as suggested like so:
<?php
$i = 0;
if(get_field('repeater_field_name')):
$i++;
if( $i > 6 )
{
break;
}
?>
<ul>
<?php while(has_sub_field('repeater_field_name')): ?>
<li>sub_field_1 = <?php the_sub_field('sub_field_1'); ?>, sub_field_2 = <?php the_sub_field('sub_field_2'); ?>, etc</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
Have you debuged the data in $the_query
with a simple print_r
?
You may find that only 3 posts are found using your query args.
Thanks
E
I figured it out – simply put, I went waaaay off the tracks when I tried this initially but failed due to a conflict with custom functions in the theme, which I discovered in troubleshooting this issue. Had I known about the conflict I wouldn’t have been trying alternative methods and forgotten about the serialized array.
Since the value for the category name is a serialized array, a comparator was required. Here’s my array code, if it might help anyone:`$args = array(
‘post_type’ => ‘testimonial’,
‘posts_per_page’ => 20,
‘meta_query’ => array(
array(
‘key’ => ‘tcat’, // from ACF custom field name
‘value’ => ‘”business”‘, // from ACF custom field checkbox options
‘compare’ => ‘LIKE’ // to match the string from the serialized ACF array
)
)
);
`
Hello, sorry to not answer to your question directly, but I proposed a different approach.
why not use an another category “slider” per example. With it, you just need to filter in the loop this category ? In the table of posts, the authors will see which post are tagged “slider” or not (In your Figure2 it is not possible actually). I thinking it will be more ergonomic for them.
Hi
I use if (++$i == 2) break;
to stop the loop at 2 rows. EG.
if( $rows ) {
$i = 0;
foreach( $rows as $row ) {
if (++$i == 2) break;
endif;
}
So you can change the 2 to a 6 to limit the number of values returned.
Hope that helps!?
I found a simple script which allowed me to show upcoming events.
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( array(
'post_type' => 'events',
'posts_per_page' => 4,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'start_date',
'paged' => $paged
) );
$current_header = '';
while ( $the_query->have_posts() ) :
$the_query->the_post();
# get the datum for this post
$temp_date = get_post_meta( get_the_ID(), 'start_date', true );
if (strtotime($temp_date) > strtotime('now')){
if ( $temp_date != $current_header ) {
$current_header = $temp_date;
include 'item-archive.php';
}?>
<?php } endwhile;?>
I also removed the pagination chaining because I couldn’t get it to work with this code.
I have one tester event that has expired, just to ensure its not showing expired events. I have it set to 4 post per page for testing, however on page 1 it only shows 3 posts, like the hidden event is still being counted.
I’ve been searching for a good solution for this all day, however I can’t find anything that will make it work.
Quick-fix
Manually importing the serialized meta value into the database worked. Note that this is required every time.
Nothing new on why this occurred
Hi @allan.crabtree
The error is quite clear. You are attempting to include a file which does not exist.
Have you used the repeater field before?
Are you using it as a normal WP plugin (wp-plugins folder)
or are you including the files within your theme?
Thanks
E
Hi @amsross
ACF requires 2 rows of data to be saved for each value.
The first row is the actual value, the other is a reference to the field key.
This reference is how ACF knows what field type / options are associated to the value, and then it will be able to return the data formatted correctly.
Perhaps you can post over the data using the field_key instead of the field_name?
This is the best way to save data with the update_field function.
Hope that helps.
Thanks
E
You can reead up on querying the posts here:
http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/
Your meta key will need to be the name of the field, and your meta value will need to be the $post_id.
Hope that helps.
Thanks
E
Hi @Romain9p
The only thing I can think of is that there is a filter running on the pre_get_posts which is overriding this setting.
Hopefuly that points you in the right direction.
Thanks
E
@souvarian and @elliot: thanks for the input.
It needs some more thorough testing but I think I have it working now. Thanks to you both.
As I have registered my field_groups using the ACF-UI, I am not using the register_field_group function. That way I don’t have the problem with the location.
How I use these funtions:
– on hook ‘admin_init’ I call
/* hooked on admin_init */
public function add_afc_head() {
if (in_array(hbd_functions::get_page_by_url(), hbd_settings::$plugin_page_names)) {
hbd_debug::write_log('acf_form_head called');
acf_form_head();
}
}
– on hook ‘admin_menu’ I build by menu using add_menu_page();
– In the callback of that function I do these actions:
do_action(‘acf/input/admin_head’);
do_action(‘acf/input/admin_enqueue_scripts’);
– Then render my page.
– In my page I call acf_form like this:
$options = array(
'post_id' => hbd_settings::AFC_POST_TOKEN, // post to save to
'field_groups' => array(hbd_settings::AFC_FORM_ID), // field group id
'form' => true,
'form_attributes' => array(
'id' => 'design-fotos',
'action' => '',
'method' => 'post'
),
'return' => add_query_arg( 'updated', 'true', (get_admin_url() . 'admin.php?page=s-advanced-search') ), // return url
'submit_value' => 'Opslaan',
'updated_message' => 'Afbeeldingvelden opgeslagen',
);
acf_form($options);
I hope this solves your question as well souverian. If it doesn’t open a new thread and let me know. I’ll look into it as well.
As long as further debugging does not surface any issues; topic solved!
Thanks for the input,
sKuijers
Display is controlled for the custom post type “course”:
<?php
/**
* The Template for displaying all single courses. Nimmo version
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
wp_enqueue_style(‘courses’, get_stylesheet_directory_uri() . ‘/lib/courses/courses.css’);
function nim_courses_content($content){
// render the ACF plugin fields.
if ( function_exists( ‘the_field’ ) ) {
// Print the CCSS/CCR logo if selected
$standard = (get_field(‘standard’));
if (!empty($standard)) {
echo ‘<div class=”standards-wrap”>’;
if( in_array( ‘College & Career Ready’, $standard ) ) echo ‘<div class=”ccr-logo”></div>’;
if( in_array( ‘Common Core’, $standard ) ) echo ‘<div class=”ccss-logo”></div>’;
echo ‘</div>’;
}
if (get_field( ‘course_description’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘course_description’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘course_description’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘learning_outcomes’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘learning_outcomes’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
echo “
“;
endwhile; ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘target_audiences’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘target_audiences’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘target_audiences’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘format’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘format’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘format’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘grades’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘grades’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘grades’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘prerequisites_required’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘prerequisites_required’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value course-field-fullwidth”>
<?php
$courseIDs = get_field( ‘prerequisites_required’ );
foreach( $courseIDs as $courseID ) {
echo ‘‘ . get_the_title($courseID) . ‘<br />’;
} ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘related_courses’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘related_courses’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value course-field-fullwidth”>
<?php
$courseIDs = get_field( ‘related_courses’ );
foreach( $courseIDs as $courseID ) {
echo ‘‘ . get_the_title($courseID) . ‘<br />’;
} ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘next_steps’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘next_steps’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value course-field-fullwidth”>
<?php
$courseIDs = get_field( ‘next_steps’ );
foreach( $courseIDs as $courseID ) {
echo ‘‘ . get_the_title($courseID) . ‘<br />’;
} ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘downloadables’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘downloadables’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value course-field-fullwidth”>
<?php
while( has_sub_field( ‘downloadables’ )):
$fileID = get_sub_field( ‘file’ );
$title = get_sub_field( ‘title’ );
echo ‘‘ . $title . ‘<br />’;
endwhile; ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘purchasables’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘purchasables’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value course-field-fullwidth”>
<?php
while( has_sub_field( ‘purchasables’ )):
$url = esc_url( get_sub_field( ‘url’ ) );
$title = get_sub_field( ‘link_title’ );
echo ‘‘ . $title . ‘<br />’;
endwhile; ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘specials’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘specials’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘specials’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘item_number’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘item_number’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘item_number’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘price’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘price’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php echo “\$” . get_field( ‘price’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
if (get_field( ‘participants’ )) { ?>
<div class=”course-field-wrap”>
<div class=”course-field-title”>
<?php $field_object = get_field_object( ‘participants’ ); ?>
<h3><?php echo $field_object[‘label’]; ?></h3>
</div> <!– .course-field-title –>
<div class=”course-field-value”>
<?php the_field( ‘participants’ ); ?>
</div> <!– .course-field-value –>
</div> <!– .course-field-wrap –> <?php
}
}
echo ‘<br />’;
//echo $content;
}
add_filter(‘the_content’, ‘nim_courses_content’);
get_header(); ?>
<div id=”primary”>
<?php get_sidebar(‘what-we-offer’); ?>
<div id=”content” role=”main”>
<?php while ( have_posts() ) : the_post(); ?>
<nav id=”nav-single”>
<h3 class=”assistive-text”><?php _e( ‘Post navigation’, ‘twentyeleven’ ); ?></h3>
<span class=”nav-previous”><?php previous_post_link( ‘%link’, __( ‘<span class=”meta-nav”>←</span> Previous’, ‘twentyeleven’ ) ); ?></span>
<span class=”nav-next”><?php next_post_link( ‘%link’, __( ‘Next <span class=”meta-nav”>→</span>’, ‘twentyeleven’ ) ); ?></span>
</nav><!– #nav-single –>
<?php get_template_part( ‘content-single’, get_post_format() ); ?>
<?php endwhile; // end of the loop. ?>
</div><!– #content –>
<?php get_sidebar(‘courses’); ?>
</div><!– #primary –>
<?php get_footer(); ?>
Field Order
Field Label
Field Name
Field Type
1 Standard (javascript:;)
standard
Checkbox
2 Course Description (javascript:;)
course_description
Wysiwyg Editor
3 Learning Outcomes (javascript:;)
learning_outcomes
Repeater
4 Target Audiences (javascript:;)
target_audiences
Checkbox
5 Format (javascript:;)
format
Checkbox
6 Grades (javascript:;)
grades
Checkbox
7 Pre-Requisites (javascript:;)
prerequisites
Post Object
8 Recommended & Related Courses (javascript:;)
related_courses
Post Object
9 Next Steps (javascript:;)
next_steps
Post Object
10 Agenda (javascript:;)
downloads
Repeater
11 Recommended Resources (javascript:;)
resources
Repeater
12 Specials (javascript:;)
specials
Wysiwyg Editor
13 Item Number (javascript:;)
item_number
Number
14 Price (javascript:;)
price
Text
15
Text
Drag and drop to reorder
+ Add Field (javascript:;)
Location
Rules
Create a set of rules to determine which edit screens will use these advanced custom fields
Show this field group if
Post TypeLogged in User TypePagePage TypePage ParentPage TemplatePostPost CategoryPost FormatPost StatusPost TaxonomyAttachmentTermUser
is equal tois not equal to
postpagecoursewpcf7_contact_formslide
and (http://mathsolutions.com/wp-admin/post.php?post=2296&action=edit#)
or
Add rule group (http://mathsolutions.com/wp-admin/post.php?post=2296&action=edit#)
Options
Order No.
Field groups are created in order
from lowest to highest
Position
High (after title)
Normal (after content)
Side
Style
No Metabox
Standard Metabox
Hide on screen
Select items to hidethem from the edit screen
If multiple field groups appear on an edit screen, the first field group’s options will be used. (the one with the lowest order number)
Content Editor
Excerpt
Custom Fields
Discussion
Comments
Revisions
Slug
Author
Format
Featured Image
Categories
Tags
Send Trackbacks
Hi guys,
I too have required this and have noticed your thread.
My needs are not too great, so I focused on simply getting the ball rolling (Which seems to work great in first tests).
This version works very similar to tabs, just add a column field – select the width – and then the fields that follow will occupy the column. If you want to reset it to a full width layout then just create another column with the reset option.
It seems to work fine with tabs, although be sure to use it inside tabs, and not tabs inside columns.
I know this needs a lot more work, such as styling and stuff – but hey we can work on that!
Anyway, https://github.com/WazzaJB/acf-field-column
Let me know how it goes if anyone gives this a try, i’d love to know how/if it works with conditional logic (Although most probably not).
Cheers
EDIT: @emcniece – I really like the idea of being able to expand fields if the user desires it. I also think it would be great to get some responsive layout into this (ie: if the browser gets too small, flatten the columns) – it’s not difficult but I just want to get it fully functioning first 🙂
Just a quick update to my last question/issue.
I got into the DB and looked at wp_postmeta
. In there I see several new fields created after manually updating the post from within the dashboard. These are _pdf_xls_0_file
, _pdf_xls
, and _pdf_xls_0_type
. In this instance, they have values of field_5244a55cc2d61
, field_51ffa871373aa
, and field_5244a63d620cd
respectively. Unfortunately, I don’t think I can correctly provide this information via XML-RPC.
Do you have any suggestions on this @elliot?
EDIT: Obviously, this works too because I can get the post_meta, but still…
for ($i=0, $x=get_post_meta($report->ID, 'pdf_xls', true); $i < $x; $i++) {
$file = wp_get_attachment_url(get_post_meta($report->ID, "pdf_xls_{$i}_file", true));
$type = get_post_meta($report->ID, "pdf_xls_{$i}_type", true);
?><a target="_blank" href="<?=$file?>"><?=$type?></a> <?php
}
Hey @elliot, I do still seem to have one issue here.
Although I am now able to send up all of this data via XML-RPC and receive it back as I expect it (via wp.getPost
), the data does not seem to be readable in the theme.
If I execute something like this:
if (get_field('pdf_xls', $report->ID)) {
while (has_sub_field('pdf_xls', $report->ID)) {
$file = get_sub_field('file');
$type = get_sub_field('type');
?><a target="_blank" href="<?=$file['url']?>"><?php the_sub_field('type'); ?></a> <?php
}
}
Then the output is <a target="_blank" href=""></a>
, which seems to indicate that the get_sub_field()
values are empty. If, however, I got into the post to edit it and hit UPDATE POST(without making any other modifications), then the theme code returns the values as expected.
Am I missing something that may rationalize the data for the WP database?
Unfortunately I don’t have direct access to the DB for this project, but I’m trying to set up an example so I can see what changes there may be before vs after the additional UPDATE.
I’ll post any findings.
Hey @elliot, thanks for the quick response!
As it happens, I was nesting my file and type field values an extra level before generating the XML call so I was sending an array like this:
array(
'pdf_xls' => 1,
array(
'pdf_xls_0_file' => 1111,
),
array(
'pdf_xls_0_type' => 'pdf',
),
);
When it should have been more like this:
array(
'pdf_xls' => 1,
'pdf_xls_0_file' => 1111,
'pdf_xls_0_type' => 'pdf',
);
My bad, just found out how to do this, if someone needs it, it is the example 5 :
Hi Elliot,
I have almost the same question but using the Repeater Field.
The Repeater Field slug is “membres_du_groupe” and inside there is the user “membre”.
The issue is that the post_meta is like :
membres_du_groupe_0_membre
membres_du_groupe_1_membre
membres_du_groupe_2_membre ...
Could you help me with this?
Thanks very much
Hi Elliot
Thank you for your response.
Yep I am using the post_object field and it’s set up as a single select field.
get_field gives me the value of the post I need but my question is how do I query with it? E.g. What would the meta_key be if I want to use it in WP_Query (get all posts with the associated post object ID of X)?
I have tried the meta query in this tutorial but it doesn’t seem to work for me: http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/
Thanks again,
Chris
Hi @elliot,
This is strange, $args are ok if I print it on core/fields/post_object.php at line 171.
Array ( [numberposts] => 7 [post_type] => emission [orderby] => date [order] => date [post_status] => publish [suppress_filters] => [sort_column] => date [sort_order] => DESC )
Yep it seems to works. Here is it what I did based on your solution:
<?php
$post_ids = get_field(' my_custom_field', false, false);
$posts = get_posts(array(
'post_type' => 'post',
'orderby' => 'post_date',
'posts_per_page' => -1,
'post__in' => $post_ids,
));
if( $posts ) {
?>
<ul>
<?php foreach( $posts as $post): ?>
<?php setup_postdata($post); ?>
<li class="line">
<a title="<?php the_title_attribute(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</li>
<?php endforeach; ?>
</ul>
<?php } ?>
Any advice are welcome. 😉
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.