Last active
October 10, 2023 19:52
-
-
Save josepedrodiaz/ed46c4119ff16b3c30889a24b7b7f9fb to your computer and use it in GitHub Desktop.
Revisions
-
josepedrodiaz revised this gist
Oct 10, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php /* * Displays an array of used modules */ -
josepedrodiaz created this gist
Oct 10, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ /* * Displays an array of used modules */ function display_used_modules() { //Name of the flexible content field $flexible_content_field_name = 'modules'; echo 'Used modules <br />'; /*pass your search string here example like this ( 's'=>'test' ) */ $args=array( 'posts_per_page' => -1, 'post_type' => 'page', ); $query=new WP_Query($args); if( $query->have_posts()): $layouts = array(); while( $query->have_posts()): $query->the_post(); { $post_id = get_the_ID(); $modules = get_field($flexible_content_field_name, $post_id); if(is_array($modules)){ $module_layouts = array_column($modules, 'acf_fc_layout'); foreach ($module_layouts as $layout) { if (!in_array($layout, $layouts)) { $layouts[] = $layout; } } } } endwhile; print_r($layouts); echo 'Total posts: ' . $query->found_posts; endif; die; } add_action('init', 'display_used_modules', 10, 0);