I'm new to Wordpress and PHP so not sure how to word this problem.
I'm developing a Wordpress blog with custom pages (2 column layout for the pages) and I'm using Advanced Custom Fields.
Anyways so I have a custom field called content_row which has a sub_field named row and that has 2 sub_fields named left_column and right_column.
For some reason I'm not able to pull the row content :(
My page.php code (on the first echo I'm getting a "bool(false)" on the screen):
<?php get_header(); ?>
<section style="margin-top:400px;">
<?php
if( get_field('content_row') ): ?>
<?php echo var_dump(has_sub_field('row')); ?>
<?php while( has_sub_field('row') ): ?>
<?php echo "test"; ?>
<?php endwhile; ?>
<?php endif; ?>
</section>
<?php get_footer(); ?>
Any ideas / thoughts? Let me know if you guys need to see more code... some screenshots below:
Got it figured out!
<?php while(the_flexible_field("row")): ?>
<?php if(get_row_layout() == "2_column"): // layout: Content ?>
<div class="content">
<?php the_sub_field("left_column"); ?>
<?php the_sub_field("right_column"); ?>
</div>
</div>
<?php endif; ?>
Related
I am hitting a bit of a brick wall with a simple WordPress problem. I am using the ACF plugin and can't seem to get it to show the field on the pages. My page.php file looks like this:
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="main">
<div id="content">
<?php if (have_posts()) : ?>
<!-- Starting the loop -->
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?>>
<h1><?php the_title(); ?></h1>
</div>
<?php the_content(''); ?>
<?php endwhile; ?>
<h2><?php the_field('bottom'); ?></h2>
<?php else : ?>
<h1>Nothing Found</h1>
<p>Sorry but we cant find anything</p>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
It's really simple as far as I can tell. Was just doing this as an exercise to get a handle on ACF before using it for something more technical and I'm stumped!
The field is 'bottom' and I just want to stick the text in there after the loop.
Screen shot of the custom field in the plugin
I'm guessing this is going to be something really simple but can't seem to find an answer anywhere!
(Posting a solution on behalf of the OP).
The answer is simple, as expected. I hadn't clicked update on the specific pages after adding the custom field template! Simple but no less frustrating. Thanks for the help.
Hello so i have had problems showing ACF fields because of an custom plugin.
I did then find out that i can instead write:
<?php $outputtext= get_field('text'); ?>
<?php echo $outputtext; ?>
instead of
<?php get_field('text'); ?>
because this didn't work when plugin was activated.
So i have been searching for an answer for a while now and been testing the same way i did get fields to also show an repeater to. No success...
And yes i have been testing regular code wich is
<?php
// check if the repeater field has rows of data
if( have_rows('topp_yrken_referenser') ):
// loop through the rows of data
while ( have_rows('topp_yrken_referenser') ) : the_row(); { ?>
<div class="col-xs-12 col-sm-4">
<blockquote>
<?php // display a sub field value
the_sub_field('topp_yrke_referens');
?>
</blockquote>
</div>
<?php } endwhile;
else :
// no rows found
endif;
?>
This is how it worked before the custom plugin and stopped to work
How do i make something like this work like i made work with this instead?
Is there an name for this $this= get_field('text'); ?
<?php if (have_rows('topp_yrken_referenser')){ ?>
<?php while (have_rows('topp_yrken_referenser')) { the_row(); ?>
div class="col-xs-12 col-sm-4">
<blockquote>
<?php the_sub_field('topp_yrke_referens'); ?>
</blockquote>
</div>
<?php }; // while: ?>
<?php }; ?>
This is as barebones as the code can get.
I have the following problem. I am using Advanced Custom Fields for Wordpress to create a subtitle field for a post. I like to give this subtitle some styling but my HTML code within the IF-statement doesn't show on the page. The $subtitle does show.
<?php $subtitle = the_field('subtitle'); ?>
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
I spent hours searching for similar problems but couldn't find any solutions. So this must probably be a rookie mistake on my part.
Solution
<?php $subtitle = get_field('subtitle'); ?>
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
Changed the_field() to get_field(). Kuddo's to Aditya Vikas!
You should echo/print it (The subtitle variable).
<div class="post-sub-title"><?php echo $subtitle; ?></div>
try using this piece of code :
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?=$subtitle?></div>
<?php endif; ?>
instead of this :
<?php if(strlen(trim($subtitle)) > 0): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
and also one more thing !
the_field() is not a default WordPress function
the 'whatever' plugin you are using might have a corresponding function:
get_field()
try this one:
<?php $subtitle = get_field('subtitle'); ?>
<?php if(!empty(trim($subtitle))): ?>
<div class="post-sub-title"><?php $subtitle; ?></div>
<?php endif; ?>
Thanks.
Here's what I'm trying to do:
I want to add some custom code so that when the featured items (which I have set to display first) have a title ex: 'Featured items'
AND
When they aren't featured I want the other (non-featured) items to have a different title ex: 'Non featured items'
So basically I'm trying achieve this by adding an if statement just before the itemListhead.
The problem is I'm not sure what the correct php functions to call ?
Here's what I've tried, but that do not work:
if ($item->featured)
if ($this->leading->item->featured)
if($params->get('FeaturedItems'))
if($this->leading->params->get->featured)
So, does anybody know how I can find out if an item is featured from the category page?
Ok, I fugured it out.
Here's the solution:
Change the following code in the itemListLeading div foreach loop in the category.php
around line 152.
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');?>
With this code:
<?php
// Load category_item.php by default
$this->item=$item;
?>
<?php if($item->featured == 1): ?>
<?php $x++; ?>
<?php if($key == 0): ?>
<div class="itemListHead">
<h2><?php echo JText::_('K2_ITEM_LIST_HEAD_FEATURED'); ?></h2>
</div>
<?php endif; ?>
<?php elseif($item->featured == 0): ?>
<?php if($key == $x): ?>
<div class="itemListHead">
<h2><?php echo JText::_('K2_ITEM_LIST_HEAD'); ?></h2>
</div>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->loadTemplate('item'); ?>
Of course, you will have to add K2_ITEM_LIST_HEAD_FEATURED & K2_ITEM_LIST_HEAD to your language overrrides.
It even works with pagination too !
So there it is, hope someone finds this usefull.
Peace.
I'm struggling with getting wordpress to search custom post meta from a page template. I've looked all over the internet and can't seem to find anything that will work. No plugins seem to work either.
On my posts, I have the custom meta: "rate" and the value: "10" - Wordpress delivers no result when searching any of these.
I'd be very appreciated if someone could write me a searchpage.php page template or point me in the right direction (I'm not good with php).
Here's my current PHP code:
<?php
/*
Template Name: Search Custom Meta
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="container clearfix fullwidth">
<div id="left-area">
<?php query_posts('meta_value='.$s); ?>
<?php if (!empty($wp_query->posts)) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>
</div> <!-- end #left-area -->
</div> <!-- .container -->
</div> <!-- #content -->
<?php get_footer(); ?>
You checking incorrect variable in if so try removing that one,
query_posts('meta_value='.$s);
while ( have_posts() ) : the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;