Last active
June 15, 2020 23:42
-
-
Save utkrishta/97a2fa55bc25e2a973473dbf855f5cc4 to your computer and use it in GitHub Desktop.
Replacing ACF with default WordPress post meta
This file contains 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 characters
<!--Accordion Section--> | |
<?php | |
/* | |
* This is an example of ACF repeater field whose name is "Content Accordion" | |
* and has sub fields: "Accordion Title" & "Accordion Content" | |
*/ | |
$accordions = get_post_meta( get_the_ID(), 'content_accordion', TRUE ); | |
if ( $accordions ) { | |
?> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-12"> | |
<div class="accordion" id="accordionModule"> | |
<?php | |
for ( $i = 0; $i < $accordions; $i ++ ) { | |
//use meta name as wrapper-name+array-key/number+field-name | |
$title = get_post_meta( get_the_ID(), 'content_accordion_' . $i . '_accordion_title', TRUE ); | |
$content = get_post_meta( get_the_ID(), 'content_accordion_' . $i . '_accordion_content', TRUE ); | |
$content = apply_filters('the_content', $content); //get content from WYSIWYG editors | |
?> | |
<div class="card"> | |
<a class="btn-link <?= ( $i == 0 ) ? 'collapsed' : '' ?>" | |
data-toggle="collapse" data-target="#collapse<?= $i ?>" | |
aria-expanded="<?= ( $i == 0 ) ? 'true' : 'false' ?>" | |
aria-controls="collapse<?= $i ?>"> | |
<div class="card-header" id="heading<?= $i ?>>"> | |
<h5 class="mb-0 font-thin accordion-title"> | |
<?= $title ?> | |
<i class="fal down-arrow"></i> | |
</h5> | |
</div> | |
</a> | |
<div id="collapse<?= $i ?>" class="collapse <?= ( $i == 0 ) ? 'show' : '' ?>" | |
aria-labelledby="heading<?= $i ?>" data-parent="#accordionModule"> | |
<div class="card-body"> | |
<?= $content ?> | |
</div> | |
</div> | |
</div> | |
<?php | |
} | |
?> | |
</div> | |
</div> | |
</div> | |
</div> | |
<?php | |
} | |
?> | |
<!--End Accordion Section--> |
make sure to DISABLE ACF ON FRONT-END
https://gist.github.com/utkrishta/c9853a10e1b48111f829a3ee8e0b6080
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For CSS and HTML styling of Accordion visit
https://codepen.io/utk_adk/pen/dyYGgqj