• Hi so I’m encountering a problem that I’ve never had before and it’s really got me at a block. So I made a menu page by using ACF and making a custom post type where every item is a post with a ACF select value to say the category. When I first added all the items everything worked. But as soon as I change content or edit a menu item it stops looping though the old ones and it seems like they don’t exist anymore. if I change an item’s time with quick edit to the time we are at it’ll show only that item now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m assuming you are using the standard foreach type of loop structure, so the problem must lie in the query or the underlying data. Would you please post your code for setting up and instantiating the query? Also, how is the ACF value getting assigned to your custom posts? When you edit something, are you editing the post object or an ACF value? If ACF, how does that get assigned to the associated post.

    Using posts to reflect ACF values sounds redundant. Why wouldn’t you use ACF values directly? You said these values are categories? Why not use taxonomy terms instead of ACF or custom posts? You are free to do what you like with your site of course, all I’m really saying is it sounds like there may be a better way. If you prefer to stay focused on the immediate problem, that’s fine.

    Thread Starter mathieugy

    (@mathieugy)

    I am essentially looping like this
    query_posts(‘post_type=menu_item’);
    if(have_posts()){
    $i = 0;
    echo ‘<ul class=”menu-bull”>’;
    while ( have_posts()) : the_post();
    id = $_POST[“id”];
    if( get_field(‘menu’) == $id){
    code here
    }
    endwhile;
    }
    wp_reset_query();

    I used custom advanced custom field since I wanted a way to make a post become a menu item. Essentially id rather focus on why only one item is showing and its the last one I edited.

    Moderator bcworkz

    (@bcworkz)

    I suspect accidental interference by other code into your query. It’s worth trying to setup the query with get_posts() and setup_postdata(). It’s what we’re supposed to use instead of query_posts(). More importantly, it changes some underlying query vars which might be enough to prevent the interference.

    If that does not help, try disabling all plugins except ACF. If still no help, isolate out the code needed for the custom post and menu listing and temporarily copy it into a default twenty* theme, then activate that theme. If still no help, the problem would be somewhere in your isolated code or ACF plugin. One of the prior actions probably stopped the problem. To determine which module caused the problem, reactivate each in turn until the problem recurs. The last activated will be the cause.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress not looping through older posts’ is closed to new replies.