Support

Account

Forum Replies Created

  • You can use the parent property in the block.json file when registering the food & drink blocks.

  • You’re doing the same thing on line 13 that you originally did on line 29 when you first shared code where you just have an if statement in a place where you’re wanting to echo your field (in the href attribute of the link spot), nothing like the_sub_field or echo get_sub_field in that spot.

  • On Line 29, you likely need to:

    1) Not close the div at the end as that div should wrap around the entire lightbox content so move the closing div tag to the end of your lightbox content

    2) As I mentioned earlier, you are storing the custom field value with a hash in your ACF field so it’s something like #flavorname. How anchors work is a #flavorname would be looking for an ID of just “flavorname” (no hash) so right now you’re spitting out the full #flavorname in both spots. It would probably be better if you move to a text ACF field vs URL and store the value without the # so the user is inputting just “flavorname” in the backend. Then in the linked part, add the hash there manually. Or you could leave the fields as is but use something like str_replace to replace the hash in the subfield in the ID spot.

  • Line 29 is where your error is. It just has an IF statement in the ID field, not anything like the_sub_field echoing an actual value. Another thing I’d keep in mind is if your ACF field is storing an anchor with a hash, the ID should be without the hash.

  • If it doesn’t work to paste in the reply (wrapped in the code tags) then you could use something like Pastebin or CodePen

  • I’d look at your code for where you’re spitting out the ACF field value for the div ID. In your non-working example, it’s just showing it standalone vs. as the ID so, your example in the source is:

    <div id="" style="display: none;">
        #baddog
    <div class="flavors">
    <div class="flavorsleft">
        <picture>
    <source type="image/webp" srcset="https://headley.tfm-dev.com/wp-content/uploads/2023/01/baddog-1.png.webp"/>
    <img src="https://headley.tfm-dev.com/wp-content/uploads/2023/01/baddog-1.png" alt=""/>
    </picture>
    
    </div>

    And where #baddog is, that should be spit out in the ID field instead. If you post the code for your template itself, may be easier to identify the error but that’s definitely what is causing it to not work. It should be:

    <div id="baddog" style="display: none;">
    <div class="flavors">
    <div class="flavorsleft">
        <picture>
    <source type="image/webp" srcset="https://headley.tfm-dev.com/wp-content/uploads/2023/01/baddog-1.png.webp"/>
    <img src="https://headley.tfm-dev.com/wp-content/uploads/2023/01/baddog-1.png" alt=""/>
    </picture>
    
    </div>
  • Wouldn’t use global $post and $post->ID within a loop inside of a block. If you change it to:

    <?php $price = get_field('print_opp_price',get_the_ID()); ?>

    Does it work?

    Thinking $post->ID is pulling the ID of the page/post this block is on and looking for the field there vs. the post in the loop.

  • Did you try to put mode false in the acf part of block.json, not supports? So in your block.json, it would be something like:

    {
        "name": "your-block",
        "title": "Your Block",
        "description": "A dummy block",
        "apiVersion": 2,
        "acf": {
            "mode": false,
            "renderTemplate": "blocks/your-block/your-block.php"
        }
    }
  • Initial thoughts would be needing:

    – User ID for current user (you’d be updating the meta for this user with the followed user’s ID) — something like get_current_user_id()
    – User ID of user being viewed (value that would be added to the meta key of the logged in user if they click the button)

    With those bits of data, you could likely:
    – use get_user_meta() to grab the current IDs (if any) of the field storing followed/liked users from the current logged in user
    – use something like maybe array_push to add the user ID of the user being viewed to the logged in user’s followed/liked group
    update_user_meta() with the new value

    If you have a function written that does this, the function could then be triggered with the button click. Not sure if any of this is helpful but hopefully 🙂

  • Did you try using:

    the_field('type_company', $post->ID)

    with both your variables in the same area as the function to see if they are being pulled correctly that route to make sure the issue isn’t with a field name error?

  • For innerblocks to work correctly you need to make sure you’re including ‘jsx’ => true in your ‘supports’ argument when registering the block, not seeing that.

    'supports' => array(
      'jsx' => true
    )
  • Yes, you need the post ID so you could add a global $post to reference the post object so something like:

    function buy_card_shortcode() {
        global $post;
        $card_details = get_field('card_id');
    
        $output = '<a class="buy-card-class" href="https://www.ebay.com/sch/i.html?_nkw='. $card_details .'">eBay</a>';
        return $output;
    }
    add_shortcode( 'buy_card', 'buy_card_shortcode' );

    I did adjust your output as I think there was an error there around where the variable was referenced, as well.

  • ACF does have a shortcode that can be used for field display:
    https://www.advancedcustomfields.com/resources/shortcode/

    LearnDash certificates should support shortcodes in the body of the certificate as I believe they’re just a custom post type.

  • This:

    $name = get_post_meta($post->ID, 'company', true);

    Should hold the value of an ACF-based or native meta key called ‘company’ if the post ID is being pulled. If it’s not working, I would try to echo out $post->ID to make sure it’s correct, if it is, double check the field name. If echo $name works, I’d look at the rest of your code as it’s not possible to know what’s in the include or what else is going on.

    Think this:

    $html = file_get_html("https://other-website-url.com/company/.$name.");

    Is where your error is, for example. Likely should be something like:

    $html = file_get_html("https://other-website-url.com/company/". $name);

  • I’ve usually done this with a date picker field that isn’t required then an alternative free text field. On the front end, I’ve then had it checking for whatever should be the priority first then falling back to the other field type. Then in the backend on the prioritized field, I usually note in the instructions that if the field is populated, it will take priority over the other.

    So maybe you have a text field that is called something like Starting Date and then a date picker field called Exact Start Date and you note that if the exact start date is populated, it will take priority over the starting date text field (in case someone populates both and you only want one)

    Something like:

    $exactDate = get_field('exact_start_date');
    if ( $exactDate ) {
      echo $exactDate;
    } else {
      // the text field
      the_field('starting_date');
    }
  • You wouldn’t likely be using default values at all within ACF for this use case, unless I’m misunderstanding what you’re doing. Default values on fields are used to have something be populated automatically/by default when creating a new item. So changing the “default value” in of a field type won’t actually change any field value on an item, it would just use that moving forward when creating future new posts.

  • If you added a true/false field to a content type and its default state is false, you would want to also check for NOT EXISTS, though, to return the full set, as ACF won’t autopopulate the false state for all posts, no? So usually if I’m working with a true/false field, my meta query is looking both for posts with the 0 value (false) in the key or posts where the key doesn’t exist at all.

  • What John noted, the error in your code, does exist, you’re going to want to change the_field to get_field. However, because you said this is also within a block and none of your fields are displaying, not just the image due to said error, it’s because you do need to pass the ID when using the_field, as well, so I would try something like:

    $image = get_field('partner_logo',get_the_ID());

    And ensure the ID is getting passed on any calls within a loop in an ACF block.

  • Is this in an ACF block? Or a template? Usually when this happens, it’s an issue with the post ID being used for the_field within the loop.

    So if, for example, you had this loop inside of an ACF block, it may be looking for those fields on the block itself, not the looped post. Or it could be looking for these fields on the page the loop is on vs. the individual looped post.

    You could try passing the post ID to the_field calls within the loop to see if that works. Without knowing really the context of where this loop exists, it’s hard to say for sure.

  • You likely also need to check to see if the meta key doesn’t exist at all with a NOT EXISTS in the compare. So you’re doing an ‘OR’ relation meta query looking for either a null state or that the key does not exist at all.

    If you have a true/false field and you save a post in the false state, it doesn’t create the key with an initial false state.

Viewing 21 posts - 51 through 71 (of 71 total)