CodeHQ

Posts Tagged ‘Custom Fields’

|

ACF – Flexible content | WordPress

Wednesday, February 24th, 2016

Useful code for Advanced custom fields (ACF) flexible content – perfect for page builders

<?php
if( have_rows('pagebuilder') ):
    while ( have_rows('pagebuilder') ) : the_row();
        if( get_row_layout() == 'hero' ):
        	
        	get_template_part( 'assets/parts/pagebuilder/hero');
     
		elseif( get_row_layout() == 'call_to_action' ):
		
        	get_template_part( 'assets/parts/pagebuilder/call-to-action');
 
        endif;
    endwhile;
else :
    // no layouts found
endif;
?>

Tags: , , , ,
Posted in PHP, WordPress | No Comments »

Query custom post type based on custom field | WordPress

Monday, October 5th, 2015

<?php 
$cityname = get_field('city_name');

$args = array(
	'posts_per_page' => '100',
	'post_type' 	 => 'neighborhood',
	'meta_key'	 => 'city_n',
	'meta_value'	 => $cityname,
	'order'	         => 'asc'
);

$cityquery = new WP_Query($args);
$i = 1;
while ( $cityquery->have_posts() ) : $cityquery-> the_post();?>

Tags: , , , ,
Posted in PHP, WordPress | No Comments »