Forums Forums Search & Filter Pro Removing "Array" value from results page.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Anonymous
    #130293

    I am using a plugin called “pods.io” to create custom posts.

    In doing this I have custom fields for post types. I can set that field as a currency, text, or a number.

    When using the Search Filter Pro plugin it says “array” in the results output instead of 0.

    Is there a way to make it say nothing if the result is 0 or simply make it say 0. I was also trying to find documentation that shows how I can output the data as a currency but haven’t found anything specific to this plugin.

    Thanks in advance for your help. I have tried finding a solution for quite awhile but haven’t had any luck.

    Trevor
    #130327

    Pods is not a 3rd party plugin that we currently support, IF it (or in that regard, this applies to any 3rd party plugin) does anything outside the normal WordPress Codex methodology (it does). Having said that, there may be ways to work around your issues.

    Are you able to send me a live link/URL to your search page so I can take a look? Can you indicate searches that I can do that will reveal these issues?

    Anonymous
    #130376

    Hi Trevor,

    Thanks for the quick reply and for your willingness to look into my question. You can find the page I was referring to here: http://admissionsdean.wpengine.com/paying_for_law_school/law-school-cost-calculator/.

    The pods.io plugin is simply setting up a custom field for each post so it should just be outputting the value of that field. In this instance, I inputted a full-time resident tuition for Albany Law School (the first link in the results) of 41845 into the custom field but it is being displayed as 41845.00. I would prefer that it is displayed as $41,845. In instances where a 0 is inputted into the custom field I am seeing the resulting text shown as “array”

    Thanks again for your help. I really appreciate it.

    Trevor
    #130414

    Are you referring to what is appearing in the results, which is generated by the results.php template? Normally that would be using our coding, but I can see from the output that you must have customized it quite a lot. Any output you see is made by that template, and the options you have used in the WordPress PHP functions to fetch the meta data. Numbers can be formatted, usually in the function itself as an argument

    Anonymous
    #130416

    That makes sense. I had looked at a few ways to do that with PHP. That said, do you know why it says “array” instead of nothing or 0?

    Trevor
    #130422

    Because if you ask for a value assuming it is a single value, and it is an array, PHP is coded to reply with ‘array’. The better way is to ask if the variable is an array (the PHP function is_array() I think), or use !is_array(), then get the value, or output 0. What would you want to do if it is an array?

    Anonymous
    #130424

    Thanks Trevor,

    My Php skills aren’t great. Thanks for the tip on the correct way to call that data. I think that gives me a good starting point to figure this one out. If it is blank or 0 I would want it to just say N/A. If it has a value I would want it to display the value.

    Thanks,
    Brad

    Trevor
    #130426

    Give me the PHP line to call a field. Put it inside code ticks (the key next (left) to the main keyboard ‘1’ key).

    Anonymous
    #130732

    Hi Trevor,

    Here is the full php file for the custom results page.

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * Note: these templates are not full page templates, rather 
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think 
     * of it as a template part
     * 
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs 
     * and using template tags - 
     * 
     * http://codex.wordpress.org/Template_Tags
     *
     */
    
    if ( $query->have_posts() )
    {
    	?>
    	<div class="resultnumber">
    	Found <?php echo $query->found_posts; ?> Results<br />
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	</div>
    	<div class="results schoolheadings">
    		<div class="cell heading schoolname">School</div>
    		<div class="cell heading">Full-Time Resident</div>
    		<div class="cell heading">Full-Time Non-Resident</div>
    		<div class="cell heading">Part-Time Resident</div>
    		<div class="cell heading">Part-Time Non-Resident</div>
    		<div class="cell heading"></div>
    	</div>
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    			<div class="results">
    					<div class="cell schoolname">
    						<h5><span class="showonmobile title">School: </span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>		
    					</div>
    					<div class="cell"><span class="showonmobile title">Full-Time Resident: $</span>
    				<?php
    					$full_time_resident = get_post_meta(get_the_id(),'full-time_resident_tuition', true);
    					echo $full_time_resident ;
    				?>
    					</div>
    					<div class="cell"><span class="showonmobile title">Full-Time Non-Resident: $</span>
    				<?php
    					$full_time_non_resident = get_post_meta(get_the_id(),'full-time_non-resident_tuition', true);
    					echo $full_time_non_resident;
    				?>
    					</div>
    					<div class="cell"><span class="showonmobile title">Part-Time Resident: $</span>
    				<?php
    					$part_time_resident = get_post_meta(get_the_id(),'part-time_resident_tuition', true);
    					echo $part_time_resident;
    				?>
    					</div>
    					<div class="cell"><span class="showonmobile title">Part-Time Non-Resident: $</span>
    				<?php
    					$part_time_non_resident = get_post_meta(get_the_id(),'part-time_non-resident_tuition', true);
    					echo $part_time_non_resident;
    				?>
    					</div>
    					
    				<div class="cell">
    					<a class="button" href="<?php the_permalink(); ?>">Learn More</a>
    				</div>
    			</div>
    		<?php
    	}
    	?>
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	
    	<div class="pagination">
    		
    		<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
    		<?php
    			/* example code for using the wp_pagenavi plugin */
    			if (function_exists('wp_pagenavi'))
    			{
    				echo "<br />";
    				wp_pagenavi( array( 'query' => $query ) );
    			}
    		?>
    	</div>
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>

    The code below is also included above and is what pushed data live to the results page

    <div class="cell"><span class="showonmobile title">Full-Time Resident: $</span>
    				<?php
    					$full_time_resident = get_post_meta(get_the_id(),'full-time_resident_tuition', true);
    					echo $full_time_resident ;
    				?>
    					</div>
    Trevor
    #130758

    Let us assume it is this one that causes the problem:

    <?php
      $full_time_resident = get_post_meta(get_the_id(),'full-time_resident_tuition', true);
      echo $full_time_resident ;
    ?>

    Then you might do this instead:

    <?php
      if (!is_arrary(get_post_meta(get_the_ID(),'full-time_resident_tuition', true))) {
        $full_time_resident = get_post_meta(get_the_id(),'full-time_resident_tuition', true);
        echo $full_time_resident ;
      } else {
        echo "N/A";
      }
    ?>
Viewing 10 posts - 1 through 10 (of 10 total)