Support

Account

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.