Bricks Builder compatibility
-
I’m trying to make the contents of a repeater appear in bricks, without success. Does anyone have any tips or guides?
-
Using the shortcode i get a warning (but no output):
Warning: foreach() argument must be of type array|object, null given inC:\Users\Dee Ego\Local Sites\bricksbuilder\app\public\wp-content\themes\bricks-c\functions.phpon line172I tries also with a code block (it’s an element like the Shortcode on bricks editor)
<?php echo do_shortcode( '[display_book_chapters id="'.$post_id.'"]' ); ?>and in this case i get 2 warnings:
Warning: Undefined variable $post_id inC:\Users\Dee Ego\Local Sites\bricksbuilder\app\public\wp-content\themes\bricks\includes\elements\code.php(160) : eval()’d codeon line2
Warning: foreach() argument must be of type array|object, null given inC:\Users\Dee Ego\Local Sites\bricksbuilder\app\public\wp-content\themes\bricks-c\functions.phpon line172
In any case, these solutions would not be ideal, as they do not take advantage of bricks’ internal query system, that is, in making the Repeater appear as a post type in the indicated dropdown.
You can update the function to check if the chapters are available.
function display_book_chapters( $id ){ $chapters = pods_field( 'book', $id, 'chapter' ); if( ! empty( $chapters ) ){ foreach( $chapters as $i => $chapter ){ echo '<div>'; echo $chapter['name']; $pdf_url = wp_get_attachment_url( $chapter['pdf'] ); if( $pdf_url ){ echo '<a href="' . $pdf_url . '">PDF</a>'; } echo '</div>' ; } } }I think the problem is that {post_id} doesn’t pass in the correct post id into the shortcode. You can test it by echoing {post_id} without the shortcode, and contact Bricks if necessary.
I don’t think $post_id can be used before declaring it. You could try {post_id}.
the Repeater is not a post type. It is a field of a Pod which can be a post type.
Updated functions: warning disappears, but no output.
in my case echoing {post_id} results in 336, which is the right one.
I also test php code above and also shortcode with hardcoded 336: no warning in this case, but neither the repeated Name/PDF.
I know that is not a post type, but the repeater (if present in page) should appears in dropwown: check the ACF version at 14:05 https://www.youtube.com/watch?t=845&v=72zSZ6AOU6YIs 336 an ID of a book page?
in my case, yes
I noticed a mistake. Please update the function this this:
function display_book_chapters( $args ){ if( isset( $args['id'] ) ){ $chapters = pods_field( 'book', $args['id'], 'chapter' ); if( ! empty( $chapters ) ){ foreach( $chapters as $i => $chapter ){ echo '<div>'; echo $chapter['name']; $pdf_url = wp_get_attachment_url( $chapter['pdf'] ); if( $pdf_url ){ echo '<a href="' . $pdf_url . '">PDF</a>'; } echo '</div>' ; } } } }using shortcode
[display_book_chapters id={post_id}]
it works!
Do you think you can integrate this to the Bricks UI, like ACF on above video?🙂 Brilliant.
I will look into it when I am less busy.
Nice! this can be a good starting point.
https://brickslabs.com/adding-any-custom-wp_query-loop-to-bricks-query-loop/
For additional question I think Bricks staff will be glad to help you.OK. Thanks.
The topic ‘Bricks Builder compatibility’ is closed to new replies.