Custom Field in WordPress -13

Custom Field in WordPress -13

Custom fields, also known to as post meta or metadata. This feature allows users to add additional information when writing a post.by using template tags in their WordPress themes. For this we use get_filed () that accepts parameters to request and fetch data via parameters. This is easily available and download from WordPress plugin by Advanced Custom fields. Example is given below for reference:

Custom query for page and custom field

<?php

$query = new WP_Query(array(

    ‘pagename’ => ‘what-we-do’,

    ‘posts_per_page’ => 3,

));

while ($query->have_posts()) {

    $query->the_post();

    ?>

<h1 class=”head-what-we-do”><?php the_title();?></h1>

  <p class=”paragraph-text”><?php the_content()?></p>

<?php

$rows = get_field(‘services’);

    if ($rows) {

        foreach ($rows as $row) {

   ?>

 <div class=”col-sm-4 p-1 “><div class=”img-content ” style=”background-image:url (‘<?php echo $row[“image”]; ?>’)”><h6><?php echo $row[“service_name”] ?></h6>

<?php

}}

  ?>

<?php

}wp_reset_query();

?>

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*