Home › Forums › ACF PRO › get_field in the functions.php file › Reply To: get_field in the functions.php file
I am using JetPack’s Infinite Scroll for the post display with updated args for the display of posts.
To update the post display on different pages I want to be able to control the category of the posts that are displayed. Here is the code:
function mm_infinite_scroll_query_args($args) {
if ( get_field('page_cat') ) {
$page_cat = get_field('page_cat');
$new_args = array(
'posts_per_page' => $args['posts_per_page'],
'paged' => $args['paged'],
'orderby' => 'date',
'order' => 'DESC',
'cat' => $page_cat,
'post_type' => array( 'post', 'features', 'it_hardware', 'videos' ),
'post_status' => 'publish',
);
return $new_args;
else {
$new_args = array(
'posts_per_page' => $args['posts_per_page'],
'paged' => $args['paged'],
'orderby' => 'date',
'cat' => 5,
'order' => 'DESC',
'post_type' => array( 'post', 'features', 'it_hardware', 'videos' ),
'post_status' => 'publish',
);
return $new_args;
}
}
Because infinite scroll runs off the page the code is all in the functions.php file hence why I want to access a field on the page which links to the loop arguments.
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.