Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Advanced Custom Field works on one page, not another WordPress

I am using the following code on my taxonomy-name.php file. It's working beautifully.

However, when trying to use the same code on a page-template.php the code does not gather the data from the field.

UPDATE: I may note that these pages are displaying terms, not posts.

<div class="<?php if(get_field('term_momentum_flag', $term)) {
echo get_field('term_momentum_flag', $term);} else { ?>momentumflag0<?php } ?>">

<?php if(get_field('term_momentum_flag', $term)) {
/*
* Displaying a single value's Label
*/
$field = get_field_object('term_momentum_flag', $term);
$value = get_field('term_momentum_flag', $term);
$label = $field['choices'][ $value ];
echo '<span class="glyphicon glyphicon-flag"></span>';

}
else { ?><span class="glyphicon glyphicon-flag"></span><?php } ?>
</div>


This is the page there I'm calling the code.

<?php
/*
Template Name: 100 List Page
*/
?>
<?php get_header(); ?>
<div class="row heading-grid">
<div class="container">
<div id="heading-position">
<div class="col-lg-12">
<h2><span class="heading-grid-title"><span class="glyphicon glyphicon-th icon-white"></span> <?php the_title(); ?></span></h2>
<div id="breadcrumbs"> <small><?php if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
} ?></small></div>
</div>
</div>
</div><!-- close container -->
</div><!-- close row services -->
<div id="spacer"></div>

<div class="container">
<div class="row">
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<article> <!-- Grid Key -->
<div class="row">
<div class="col-lg-12">
<?php include("grid-key.php"); ?>
</div>
<div class="col-sm-12 col-xs-12 hidden-lg hidden-md">
<?php include("sidebar100list-mobile.php"); ?>
</div> <!-- End col-12 -->
</div>
<?php if(!empty($_REQUEST['noresults'])) echo '<div class="alert alert-warning">The equity "'. htmlentities ($_REQUEST['noresults']) .'" you just searched was not shortlisted for inclusion in our Alpha Grid database because other equity instruments in this sector and/or alternative industries have been assessed with better sentiment-driven alpha opportunities at this time. Your symbol of interest will be added when it meets our stringent screening criteria for getting rated with at least a one star status.</div>'; ?>
<!-- Grid Key -->
<!-- Content Protection -->
<?php ob_start();?>
<!-- Content Protection -->
<div class="row" >
<?php

global $alpha_total_number_of_pages;

$args = array (
'output_taxonomy' => '100gridgroups',
'order_by_taxonomy' => 'grid-star-rating',
'current_page' => (get_query_var( 'paged' ))? get_query_var( 'paged' ) : 1
);
$libcats = mon_get_alpha_terms( $args );
# Note: if starts here checking if $libcats not false
if($libcats) {

$i = 0;
foreach($libcats as $lc){
if( $i % 4 == 0 )


{ ?>
<div class="clearfix"></div>
<?php }
$i++; ?>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-6" >
<?php $termlink = get_term_link( $lc->slug, '100gridgroups' ); ?>
<div class="panel panel-default">
<div class="panel-image">

<div class="thumbnail">
<div class="caption hidden-md hidden-sm hidden-xs">
<br/>
<h5><?php echo $lc->name; ?> </h5>


<!-- Popover Start -->
<div class="po-markup" ><a href="<?php echo $termlink;?>" class="p5598 popover-dismiss btn btn-info btn-lg"><?php echo $lc->count ?> Symbols</a>
<br/><h4><a class="label" href="<?php echo $termlink;?>">Open Group</a></h4>

<div class="po-content hidden popover">
<div class="po-title">
<div class="row"><div class="col-lg-9">
<!-- sell signal indicator -->
<span class="pull-left"><?php
if(mgm_user_is(array('focus15','trendpiece'))) {

<strong>include("term-momentum-flag-mobile.php");</strong>

} else {
echo '';
} ?> </span>
<!-- sell signal indicator -->
<h4><?php echo $lc->name; ?> Symbols </h4></div><div class="col-lg-3"><h4><span class="label label-info pull-right"><?php echo $lc->count ?> Active</span></h4></div></div>

</div> <!-- ./po-title -->
<div class="po-body">

<?php if(mgm_user_is(array('grid100','trendpiece','focus15'))) {
include("symbol-list-popover.php");
} else {
echo '<div class="widget-area"><div class="alert alert-info"><span class="glyphicon glyphicon-eye-close"></span> You need to be a Grid 100, Trend Piece, or Focus 15 subscriber to see the full content.<br/><br/> <a class="btn btn-md btn-info" href="http://www.runningalpha.com/subscriptions/grid100/"> Sign Up for Grid 100</a></div></div>';
}?>

<br/>
<a class="btn btn-navy btn-block" href="<?php echo $termlink; ?>">View All <?php echo $lc->count ?> Symbols</a>

</div><!-- ./po-body -->
</div> <!-- ./po-content -->
</div><!-- ./po-markup -->

<!-- Popover End --> <br/>


</div>

<!-- Get Image by Attachment ID Start-->
<?php
$attachment_id = get_field('taximage', '100gridgroups_'.$lc->term_id);
if ($attachment_id) {
$image = wp_get_attachment_image_src($attachment_id, 'industrygroup-img');
if ($image) {
?>
<img class="img-responsive" src="<?php echo $image[0]; ?>" />
<?php
}
}
else { ?>
<a class="mobile-group-link" href="<?php echo $termlink; ?>"><img class="img-responsive" src="http://www.runningalpha.com/wp-content/uploads/2014/09/RA-logo-300px-groups.jpg" alt="<?php the_title(); ?>" /></a>
<?php } ?>
<!-- description div -->
<div id="deschide">
<div class="<?php if(get_field('level_of_interest', '100gridgroups_'.$lc->term_id)) {
echo the_field('level_of_interest', '100gridgroups_'.$lc->term_id);

} else { ?>intleveldefault<?php } ?>">
<!-- description content -->
<div class="description_content"> <a href="<?php echo $termlink; ?>"><?php echo $lc->name; ?></a> </div>
<!-- end description content -->
</div> </div>

<!-- end description div -->

</div>

<!-- Get Image by Attachment ID End-->



</div>

<div class="panel-footer text-center">
<!-- Icons -->
<div class="row">
<!-- LG Screen -->
<div class="col-lg-4 visible-lg">
<div class="<?php if(get_field('heat_level', '100gridgroups_'.$lc->term_id)) {
echo the_field('heat_level', '100gridgroups_'.$lc->term_id); } else { ?>heatleveldefault<?php } ?>"></div>
</div>

<div class="col-lg-8 visible-lg">
<div class="<?php echo mon_get_rating_class($lc->rating); ?>"></div></div>
<!-- LG Screen -->
<!-- MD, SM, XS Screen -->
<div class="hidden-lg col-md-12 col-sm-12 col-xs-12">
<center> <div class="<?php if(get_field('heat_level', '100gridgroups_'.$lc->term_id)) {
echo the_field('heat_level', '100gridgroups_'.$lc->term_id); } else { ?>heatleveldefault<?php } ?>"></div></center>
</div>

<div class="hidden-lg col-md-12 col-sm-12 col-xs-12">
<center> <div class="<?php echo mon_get_rating_class($lc->rating); ?>"></div></center></div>
<!-- MD, SM, XS Screen -->


</div><!-- end row -->
<!-- Icons -->
</div>
</div>
</div>



<?php } ?>
</div>
<!-- Pagination Start -->
<div class="text-center">
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(
array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '/page/%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $alpha_total_number_of_pages,
'type' => 'list',
'end_size' => 5,
'mid_size' => $mid_size,
)
);
?></div>
<!-- Pagination End -->
<?php
//Note: and ends here
} else {
echo '<div class="col-lg-12"><div class="alert alert-info">Sorry, this page does not have any active industries at this time. Please check back soon.</div></div>';
}
?>
<!-- Content Protection -->
<?php echo do_shortcode('[private]'.ob_get_clean().'[/private]' ); ?>
<!-- Content Protection -->
</article>

</div> <!-- End col-md-9 -->
<div class="col-lg-3 col-md-3 hidden-sm hidden-xs">
<?php include("sidebar100list.php"); ?>
</div> <!-- End col-md-3 -->
</div><!-- End row -->
</div><!-- End Container -->
<?php get_footer(); ?>

Answers (2)

2014-12-06

Arnav Joy answers:

I think in place of this
get_field('term_momentum_flag', $term)

You have to use this
get_field('term_momentum_flag')

So you just have to use field name


streetfire comments:

I wish that did it, but It did not :(

2014-12-06

Sabby Sam answers:

Hi there,
I think you should check this first thing.
1. Cross checks if the page field value is empty.
if it is not empty, then try this one.
2. get_the_id : get_field('term_momentum_flag', get_the_id ()). Make sure it should get the id of the page or taxonomy.
Thanks


streetfire comments:

Hi there, to my knowledge the field value is not being gathered by the code. So #1 is empty I believe. It's displaying the default data.


Sabby Sam comments:

Hi Street Fire,
May be you are right. I saw this documentary and that's what I have written.
http://www.advancedcustomfields.com/resources/get_field/.
I am not sure but check this
$field_name: the name of the field to be retrieved. eg “page_content” (required)
$post_id: Specific post ID where your value was entered. Defaults to current post ID (not required). This can also be options / taxonomies / users / etc
$format_value: whether or not to format the value loaded from the db. Defaults to true (not required).


streetfire comments:

Hm, I tried this, but no luck. I find it off the same code works on one page, but not another. baffling.

<div class="<?php if(get_field('term_momentum_flag', '100gridgroups')) {
echo the_field('term_momentum_flag','100gridgroups_'.$term);} else { ?>momentumflag0<?php } ?>">

<?php if(get_field('term_momentum_flag','100gridgroups')) {
/*
* Displaying a single value's Label
*/
$field = get_field_object('term_momentum_flag','100gridgroups');
$value = get_field('term_momentum_flag','100gridgroups');
$label = $field['choices'][ $value ];
echo '<span class="glyphicon glyphicon-flag"></span>';

}
else { ?><span class="glyphicon glyphicon-flag"></span><?php } ?>
</div>


streetfire comments:

Copied above code wrong, this is what I tried and no luck

<div class="<?php if(get_field('term_momentum_flag', '100gridgroups')) {
echo the_field('term_momentum_flag','100gridgroups');} else { ?>momentumflag0<?php } ?>">

<?php if(get_field('term_momentum_flag','100gridgroups')) {
/*
* Displaying a single value's Label
*/
$field = get_field_object('term_momentum_flag','100gridgroups');
$value = get_field('term_momentum_flag','100gridgroups');
$label = $field['choices'][ $value ];
echo '<span class="glyphicon glyphicon-flag"></span>';

}
else { ?><span class="glyphicon glyphicon-flag"></span><?php } ?>
</div>


streetfire comments:

uhhg, Finally got it! Now my head hurts.

<div class="<?php if(get_field('term_momentum_flag', '100gridgroups_' . $lc->term_id)) {
echo get_field('term_momentum_flag','100gridgroups_' .$lc->term_id);} else { ?>momentumflag0<?php } ?>">

<?php if(get_field('term_momentum_flag','100gridgroups_' . $lc->term_id)) {
/*
* Displaying a single value's Label
*/
$field = get_field_object('term_momentum_flag','100gridgroups_' . $lc->term_id);
$value = get_field('term_momentum_flag','100gridgroups_' . $lc->term_id);
$label = $field['choices'][ $value ];
echo '<span class="glyphicon glyphicon-flag"></span>';

}
else { ?><span class="glyphicon glyphicon-flag"></span><?php } ?>
</div>