Update here, endpoint is showing only posts that have status sticky + custom files: yes
If post is only sticky, it will not show
If post have only custom filed: yes, it will not show.
Post will only show if have sticky + custom filed: yes
I have write in many wordpress groups, but no one know how i can solve this.
here is my updated code:
add_action( 'rest_api_init', 'api_hooks' );
function api_hooks() {
register_rest_route( 'get-post-sidebar/v1', '/go', array(
'methods' => 'GET',
'callback' => 'get_post_sidebar',
) );
}
function get_post_sidebar($request_data){
// $data = $request_data->get_params();
$data = array()
;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'id',
'order' => 'DESC',
'meta_key' => 'recommended_sidebar',
'meta_value' => 'yes',
'compare' => '=',
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) {
$the_query->the_post();
array_push($data,
array(
'title' => get_the_title(),
'content' => get_the_content(),
'date' => get_the_date('Y-m-d H:i'),
'number_of_comments' => get_comments_number(),
'author' => get_the_author(),
'id' => get_the_ID(),
'link' => get_post_permalink(),
'thumbnail' => get_the_post_thumbnail_url()
)
);
}
wp_reset_postdata();
$response = new \WP_REST_Response( $data );
$response->set_status( 200 );
return $response;
}
Hello,
I have do a custom query.
But for some reason, only sticky posts will show up in endpoint. Not a custom filed posts.
I post my query here:
https://wordpress.stackexchange.com/questions/384526/json-create-rest-api-endpoint-for-advanced-custom-fields
I hope there is something that i can do to fix my query.
Best Regards
Thank you @hube2
So i will need to create custom endpoint ?
It is not possible to just filter endpoint that i allredy have?
Regards
Hi there,
I found this amazing plugin: https://wordpress.org/plugins/acf-to-rest-api/
Now when i open json at /wp-json/wp/v2/posts i can see filed ACF
And there i can see fileds recommended_sidebar: yes or recommended_sidebar: no
But this JSON will show all posts.
Is it possible to make some filter for posts?
I will like to show only posts that have recommended_sidebar: yes ?
Thank you!
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.