Support

Account

Forum Replies Created

  • It’s not returning anything, and a var_dump of $accounts returns an empty array.

    Also, I had been using the double quotes in past iterations and it doesn’t solve the problem. I’ve added them back into the code per your comment above.

  • The code is part of the bank CPT single-post template. I’ve tried many iterations, but here’s where it currently stands:

    <?php
    /*
     * Template Name: Bank Review Test
     * Template Post Type: banking
     */
    
    add_action ( 'genesis_before_entry_content', 'banking_data');
    
    function banking_data(){
    
        $post_id = get_the_ID();
    
        $accounts = get_posts(array(
            'post_type'         => array('bank_accounts','money_market_account','checking_accounts'),
            'posts_per_page'    => -1,
            'meta_query'        => array(
                array(
                    'key' => 'bank_relationship', // name of custom field
                    'value' => $post_id, // matches exactly "123", not just 123. This prevents a match for "1234"
                    'compare' => 'LIKE',
                )
            )
            ));
    
            if( $accounts ): 
            ?>
                <ul>
                <?php foreach( $accounts as $account ): ?>
                
                    <li>
                            <?php echo get_the_title( $account->ID ); ?>
                        </a>
                    </li>
                <?php endforeach; ?>
                </ul>
            <?php endif;
    
    }
    
      genesis();
    
    ?>

    Note that the 3 post types all use the same ACF relationship field that points to the bank CPT. I’ve also tried hard-coding the post ID with no success.

  • Correct on both accounts. The relationship field is on the account CPT and points to the Bank CPT. It’s not a sub field, group, repeater or flex field.

  • A relationship field, and it doesn’t allow for multiple selections.

  • Thank you for the reply. This is exactly the code I’ve been using with no luck. Curious if it matters what return format I use for the relationship field.

    I should add that the code doesn’t work even if I hard-code the post id.

  • Has the first question above ever been answered. How do we use the ACF Gutenberg block feature to display custom fields that are tied to Custom Post Types?

  • Interesting. Ok, well thanks for your input.

  • It’s not a post attachment. The image url is saved in an ACF field. The above code is pretty standard.

  • Well, my code works, I just need to convert the image id to the image url. An extra step that does’t make sense given that the image field I’m retrieving is set to return the url.

  • bank_institution is a relationship field and bank_logo is an image field.

  • Here’s the code:

    function bank_acct_box($atts) {
    	$id            = $atts['post_id'];
    	$childtag	   = $atts['child'];
    	$name          = get_field('bank_account_name', $id);
    	$link          = get_field('bank_account_affiliate_link', $id);
    	$bullets       = get_field('bank_account_key_features', $id);
    	$bank 		   = get_field('bank_institution', $id);
    	$image		   = $bank[0]->bank_logo;
    	$image		   = wp_get_attachment_url($image);
    	$btn 		   = "<a class='btn btn-primary radius mt-3' href='$link/$childtag-btn' target='_blank' rel='nofollow'><strong>Open an Account</strong></a>";
    
    	$bankbox   = "<div class='row bg-light p-3 mb-3 border'>
    			   <div class='col text-center'>
    			   <a class='btn btn-link mb-2' href='$link/$childtag-tl' target='_blank' rel='nofollow'><strong>$name</strong></a>
    			   <img border='0' alt='$name' src='$image'>
    			   </br>$btn
    			   </div>
    			   <div class='col-8'>$bullets</div>
    			   $image<br></div>";
    
    	return	   "$bankbox";
    }
    
    add_shortcode( 'bankacct_box', 'bank_acct_box' );

    Without this line ($image = wp_get_attachment_url($image);) it returns the image id, even though the field is set to return the image url AND it works when I’m not requesting it through the relationship field.

Viewing 11 posts - 1 through 11 (of 11 total)