I have an issue that I encountered, and can’t figure it out. I have two post types: artists, projects.
For artists I have added a relationship ACF field, that relates to the ‘projects’ posts. On the artists archive page I’ve created a search form, one of the fields is a selectbox that should list the relationship values.
How can I fill that selectbox with the relationship field values?
How should the WP_Query look like with the relationship field integrated?
If someone did such a thing, or can post some code snippets that would be really helpful!
this plugin can be only 2 option for get list:
– get from a repeater field created in option page (ACF Pro)
– get from a post (single post ID)
i read again your problem, this field doesn’t for you.
you can create a small query like relationship field and then create you select list. something like this:
<?php $args = array( 'posts_per_page' => 5, 'offset' => 0, 'category' => '', 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'post', 'post_mime_type' => '', 'post_parent' => '', 'post_status' => 'publish', 'suppress_filters' => true ); ?> <?php $posts_array = get_posts( $args ); ?> <select> <?php foreach ( $dynamicposts as $post ) : setup_postdata( $post ); ?> <option value="<?php echo get_permalink(); ?>"><?php echo get_permalink(); ?></option> <?php endforeach; ?> </select> <?php wp_reset_postdata(); ?>
The code you posted is something that I have at the moment, yes it lists all of the projects, but the issue is that I can’t figure out what should I add in the WP_Query, tried
'post_type' => array('projects','artists') but the issue is that that code would list the ‘projects’ posts, and not the related posts.
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.