Could you clarify exactly how did ACF4 work and how does ACF5 works?
Yes I was running ACF 4 before the switch. Is there an article on changes from 4 to 5?
Thanks John,
within the debugger, pre_get_posts was invoked twice. I have added this enforcement if($query->is_admin && $query->query['post_type'] == "post")
{and now things are working as usual
I have recently updated ACF plugin after months. Now, a get_field in pre_get_posts will crash in a loop. Offending code: $variable = get_field(‘class’, $usrid);
Same command for same user, run in other parts of the code, will work. Could it be that the logic has changed and ACF is not initialised when pre_get_posts is being run?
// ********** post & media lists filtered by user role & category ****************
add_filter(‘pre_get_posts’, ‘posts_for_current_role’);
function posts_for_current_role($query) {
if($query->is_admin) {
global $students_allowed_cat;
global $teachers_allowed_cat;
global $pagenow;
global $acorn_user;
if (‘edit.php’ == $pagenow) {
//var_dump($query);die();
if ($query->get(‘cat’) == ‘0’ || IsNullOrEmptyString($query->get(‘cat’)) || !count($_GET)) {
if (in_array(‘teacher’, (array)$acorn_user->roles)) {
// Allowed all at the moment $filtered_cat = $teachers_allowed_cat;
//$query->set(‘cat’, $filtered_cat);
}
if (in_array(‘student’, (array)$acorn_user->roles)) {
//The user has the “student” role
$usrid = “user_” . $acorn_user->ID;
$variable = get_field(‘class’, $usrid);
switch ($variable[0]) {
case ‘Year 7’:
$studcat = array(157, 158);
break;
case ‘Year 8’:
$studcat = array(402, 403);
break;
case ‘Year 9’:
$studcat = array(150, 152);
break;
}
$query->set(‘category__in’, $studcat); //$students_allowed_cat
}
}
if (empty($_GET[‘author’])) {
if (in_array(‘student’, (array)$acorn_user->roles)) {
$members = get_users(‘role=student&fields=id’);
//var_dump($members); die();
if (empty($members)) {
$members = array(0);
}
$query->set(‘author__in’, $members);
} else {
$query->set(‘author’, ‘-1’);
}
}
}
}
return ($query);
}
Thanks John,
Teachers, Students and parents already exist in my scenario (as custom roles) however I miss “Courses/classes” and relationships to users depending on roles, Could I achieve this with custom post types?
For instance, user Paul is a student, attending “Math 4”, his sister Lisa is a student attending “Literacy 2”, Mary is a parent (mum of Paul and Lisa), Andrew is teaching in all courses.
Could all the relationships above be managed with custom post types?
John, does the Pro basic license (1) allow to install and work on both production and offline versions of the same site? Basically I develop locally on my PC and push updates to the online site…
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.