Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im using Artiss Currency Converter to convert some numbers on my website. Im trying to out put do_shortcode('[convert number=1 from="aud" to="jpy"]') in 2 pages. One is a template page in mythemefolder/newtemplate.php and the other is in mythemefolder/functions/single_product.php

do_shortcode('[convert number=1 from="aud" to="jpy"]') works Perfect in newtempalte.php but it doesn't seem to work in single_product.php.

Why is that? How can I fix it and does it matter where the php file is for do_shortcode to work?

This is the funciton in single_product.php

    function cps_ajax_search($meta_boxes){
    $posts = cps_search_posts();?>

<?php get_template_part("sidebar-left-common");?>

<?php require_once(TEMPLATEPATH."/functions/var/default-box-one.php"); ?>
<div class="detail-page-content hideOnSearch">

 <!-- detail page content starts -->

<div class="searchBreadcrumbs"><!--  breadcrumbs starts -->
        <?php  '<a href="#" class="cpsBack">Home</a> &raquo;';?> 
        <?php cps_breadcrumbs(); ?>
    </div> <!-- breadcrumbs ends -->
    <div style="clear:both"></div>  
<div class="sort-by-bar"> <!-- sort bar starts -->
<div class="searchSort"> <!-- search sort starts -->
<?php _e('Sort By:','language');?>
<?php cps_sort_by('miles') ?> - 
<?php cps_sort_by('year') ?> -
<?php cps_sort_by('price') ?>

</div> <!-- search sort ends -->
</div> <!-- sort bar ends -->
<div style="clear:both"></div>
<?php wp_reset_postdata();?>
        <?php
            $displayed = array();
             if(!empty($posts)): foreach($posts as $post): 

                if(in_array($post->ID,$displayed)):
                    continue;
                else:
                    $displayed[] = $post->ID;
                endif;
            ?>
<?php global $options;$fields;$options2;$options3;$symbols;
              $fields = get_post_meta($post->ID, 'mod1', true);
              $options2 = get_post_meta($post->ID, 'mod2', true);
              $options3 = get_post_meta($post->ID, 'mod3', true);
              $symbols = get_option('gorilla_symbols');
              $options = get_option('gorilla_fields'); ?>           
<?php $blogurl = get_bloginfo('template_url'); ?>
<?php $surl = get_bloginfo('url'); ?>   
<div class="result-car"><!-- result car -->
<?php       
    $args = array(
    'order'          => 'ASC',
    'orderby'        => 'menu_order',
    'post_type'      => 'attachment',
    'post_parent'    => $post->ID,
    'post_mime_type' => 'image',
    'post_status'    => null,
    'numberposts'    => 1,
    );

    $attachments = get_posts($args);
    if ($attachments) {


        foreach ($attachments as $attachment) {

        echo '<a href='.$surl.'/'.$post->post_name.'>'.wp_get_attachment_image($attachment->ID, 'thumbnail_results').'<span class="'.$fields['statustag'].'"></span></a>';
    }
} ?> 
                        <div class="result-detail-wrapper">  <!-- result detail wrapper -->
                            <p><a href="<?php echo $post->post_name ?>" rel="bookmark" title="<?php echo $post->post_title ?>"><?php if ( $fields['year']){ echo $fields['year'];}else {  echo ''; }?> <?php echo $post->post_title ?></a></p>
                            <p><strong><?php if (isset( $fields['miles'])){
                            ##### New ##########
                            //number_format($fields['miles'],0,'.','.')
                            echo number_format($fields['miles'],0,'.',',').' '.$options['milestext'];
                            ##### End ##########
                            }else {  echo ''; };?></strong></p>
                            <p><?php if (isset( $fields['vehicletype'])){ echo $fields['vehicletype'].' | ';}else {  echo ''; };?> <?php if (isset( $fields['transmission'])){ echo $fields['transmission'];}else {  echo ''; };?><br/><?php if (isset( $options2['cylinders'])){ echo $options2['cylinders'].' '.$options['cylinderstext'].' | ';}else {  echo ''; };?><?php if (isset( $fields['interior'])){ echo $fields['interior'].' | ';}else {  echo ''; };?><?php if (isset( $fields['epamileage'])){ echo $fields['epamileage'];}else {  echo ''; };?></p>
                            <p class="result-price"><?php include(TEMPLATEPATH."/functions/var/default-box-one.php");
                            //echo $symbols['currency'];     
                            ##### New ##########
                            // echo number_format($fields['price']);  
                            ##### End ##########

                          ?>

                          <span id="calPriceInAud<?php echo $callPriceInAudCounter; ?>">Calculating...</span>

                            <script>
                            //Calculator.js
                            //function CarCostCalculator(enteredPriceInYen,cubicMeters,complianceFee,serviceFee,inventoryItemID)
                            CarCostCalculator(<?php echo $fields['price']; ?>,14, 2500, 1100,<?php  echo do_shortcode('[convert number=1 from="usd" to="aud"]');?>)
                            </script>
                             </p>

                         </div> <!--   result detail wrapper ends -->
 </div> <!-- result car ends --> 
            <?php endforeach; else: ?>
                <p style="padding:30px;"><?php _e('Sorry, no listings matched your criteria.','language');?></p>
            <?php endif; ?>
            <div class="bottom-pagination"> <!-- Pagination starts -->
                        <p><a id="link" href="#top"><?php _e('BACK TO TOP','language');?></a></p>
                        <p class="paging">
                            <?php cps_show_pagination() ?>
                        </p>
                  </div>  <!-- Pagination ends -->  
                </div>
    <?php

    exit;
}

As you can see

CarCostCalculator(<?php echo $fields['price']; ?>,14, 2500, 1100,<?php echo do_shortcode('[convert number=1 from="usd" to="aud"]');?>)

has do_shortcode('[convert number=1 from="usd" to="aud"]') but it doesnt work. But works fine on the template file.

share|improve this question
    
@s_ha_dum, thanks for editing. :) –  user1889007 Feb 24 '13 at 1:49
1  
I can't tell the problem based on the information provided. Please post the code that doesn't work, for starters. Post the code in context-- that is, all of the relevant code. That probably means the whole function. –  s_ha_dum Feb 24 '13 at 1:52
    
You should indent correctly. You have no excuses for poor formatting other than pure lazyness, and a desire for accidental bugs. Your editor should have auto-indenting. Also you're using post meta, but nowhere have you checked if the meta actually existed, you just 'assume' it does. –  Tom J Nowell Feb 24 '13 at 2:02
    
@TomJNowell : Thanks. This code wasnt coded by me, its a plugin I bought, so Im not quite sure how post mata works. Im just wondering hwo to get do_shortcode('[convert number=1 from="usd" to="aud"]') to work? –  user1889007 Feb 24 '13 at 4:18
    
If you bought this plugin what did the people who you bought it off say when you went to them to ask for support? If you came here first instead can I ask why you did so instead of going to the people best able to answer your question? –  Tom J Nowell Feb 24 '13 at 19:29
show 3 more comments

2 Answers

global $options;$fields;$options2;$options3;$symbols;

That is the same as:

global $options;
$fields;
$options2;
$options3;
$symbols;

You've declared options as a global, but the other variables are just stated, they're doing nothing, those lines might as well not be there.

Next we have:

$fields = get_post_meta($post->ID, 'mod1', true);

But you're not checking if it's an error value.

if (isset( $fields['miles'])){
                            ##### New ##########
                            //number_format($fields['miles'],0,'.','.')
                            echo number_format($fields['miles'],0,'.',',').' '.$options['milestext'];
                            ##### End ##########
                            }else {  echo ''; }

So the reason you are getting nothing, is because the miles field is not set. So it prints '', aka nothing. Try replacing the '' with 'error' and you'll see 'error' printed.

Also finally, short codes are intended for content. Instead you're calling the short code indirectly, and outside of the loop.

The short code may make references to the current post, and you would be better off calling the actual function the short code is bound to instead of using do_shortcode

share|improve this answer
    
Thanks for writing. Actually Im trying to edit an extension I bought for WP. So not quite sure whats going on in there. The $fields['miles'] outputs values fine. The problem I have is the other plugin I installed Artiss Currency Converter doenst output do_shortcode('[convert number=1 from="usd" to="aud"]') –  user1889007 Feb 24 '13 at 2:14
    
But by your own admission it doesn't, look at your question, see where you said"CarCostCalculator(,14, 2500, 1100,)"? Notice the comma where the first value is missing? –  Tom J Nowell Feb 24 '13 at 19:24
    
Sorry, the editor has stripped out the <?php echo do_shortcode('[convert number=1 from="usd" to="aud"]');?> part from the question, I just fixed it. –  user1889007 Feb 24 '13 at 22:11
add comment

I figured out why some pages don't allow do_shortcode. This can apply to ANY Wordpress plugin so any one can use this trick. I included the plugin's functions php file

<?php require_once($dir = ABSPATH . "/wp-content/plugins/artiss-currency-converter/includes/acc-functions.php"); ?>

and used its function to calculate the rates

get_conversion( 'number=1&from=aud&to=jpy' )

That's it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.