WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Unexpected behavior of checkbox (2 posts)

  1. jpisanu
    Member
    Posted 1 year ago #

    I'm facing a weird issue trying to do what I'm going to explain now.

    Context

    Plugins I'm using: Custom Post Type UI / Advanced Custom Fields Functionality: I have a custom post type called "vendors". Within this post type I have several custom fields made on ACF. One of these fields is Called "Promote to Homepage" which is set as a checkbox. So the idea is simple, if that checkbox is checked show that post on the homepage.

    So this seemed to work fine, but when I tried to change that "Highlighted Vendor" to another one (unchecked current, checked desired to avoid conflicts I found that the post I was setting as featured wasn't showing, nothing was shown.

    I started testing then trying with other vendor posts, to find that this behavior is completely random, some of them published correctly to homepage, some others not. I tried to find out a pattern to identify what might be causing it and failed. Also tried to replicate the settings of a vendor that was failing to publish within a vendor that was publishing fine, and even setting the exact same things the vendor was still publishing.

    Finally I should mention that I have a page where I'm listing some kind of "directory" where all vendors are being shown. I added a simple code to check if the "promote_to_homepage" output was correct, something like "if the checkbox is checked, say hi" and found that the posts that aren't showing on homepage, pass the test on directory page.

    I'm running out of ideas about what this could be, that's why I'm trying here if someone can bring me some help.

    The code I'm using in the homepage is simple:

    <?php query_posts('post_type=vendors');
    while (have_posts()):the_post();
    $featured = get_field('promote_to_homepage', $post -> ID, true);
    if ($featured){?><!-- show the content here -->
    <?php }; endwhile; ?>

    That's all.

    Thanks in advance to anyone that can help me on this.

    Juan.-

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. jpisanu
    Member
    Posted 1 year ago #

    In dozens of posts I have wrote on WP forums, I had answers in 1 of them. Such an unhelpful community....

    Anyways for any other that might have this problem, let me tell you that I found what was causing this.

    I started suspecting that some of the posts promoted to homepage were behind the pagination and that's why they were not shown. So I changed to posts_per_page to an infinite and then the highlighted vendor is shown.

    I still not understand the why of this behavior, because it's supposed the query + if statement should return 1 single post (the one chosen) so if I even had 1 post per page, it should work.

    Anyways...I hope that this post could help someone at some time.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.