Displaying Service Post Content and Pricing

Posted · Add Comment

Scheduler Forums BirchPress Scheduler Displaying Service Post Content and Pricing

This topic contains 5 replies, has 3 voices, and was last updated by  itwd.ian 10 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2332

    Jon Harmon
    Participant

    I’ve been trying to figure out how to display the custom services posts with title, description and pricing and I’ve been successful displaying services with title and description but can’t seem to display the price.

    Below is my current code to display all services with title and description and my attempt at displaying the price.

                          
    <?php
       $tax_query = array( 'relation' => 'AND' );
       $args = array(
       'post_type' => 'birs_service',
       'tax_query' => $tax_query,
      'posts_per_page' => 100
       );
       $custom_loop = new WP_Query( $args ); 
       if ( $custom_loop->have_posts() ) :
       while( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?>
      <article class="spa_service">
       <h1><?php the_title(); ?></h1>
        <p><?php  the_content(); ?></p>
         <p><?php  get_post_meta($post->ID, 'birs_service_price'); ?></p>
    
         <br style="clear:both">
        </article>       
                                      
         <?php    endwhile;
           else :
            _e('Sorry, No Services Available Currently.');
           endif;
                          wp_reset_query(); ?>  
    
    #2333

    support
    Keymaster

    Hi Jon,

    The price meta field should be ‘_birs_service_price’ other than ‘birs_service_price’.

    If you have any other questions, please feel free to contact us.

    #2407

    itwd.ian
    Participant

    Hi,
    I really like the look of this and have added it to an Advanced Text Widget (one that can handle PHP) my code though does’t show the price either.
    here it is:

    <?php
       $tax_query = array( 'relation' => 'AND' );
       $args = array(
       'post_type' => 'birs_service',
       'tax_query' => $tax_query,
      'posts_per_page' => 100
       );
       $custom_loop = new WP_Query( $args ); 
       if ( $custom_loop->have_posts() ) :
       while( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?>
      <article class="service">
       <h6><?php the_title(); ?></h6>
        <p><?php the_content(); ?></p>
         <p><?php get_post_meta($post->ID, '_birs_service_price'); ?></p>
         <br style="clear:both">
        </article>       
                                      
         <?php    endwhile;
           else :
            _e('Sorry, No Services Available Currently.');
           endif;
    wp_reset_query(); ?>

    Any idea what’s wrong?

    #2408

    Jon Harmon
    Participant

    Here is what I am using to retrieve and display the price now.

    <?php $price = get_post_meta($post->ID, '_birs_service_price', true); ?> 
    <p class="pricing"><span>$</span><?php echo $price; ?></p> 
    
    #2598

    itwd.ian
    Participant

    I’m able to display price when adding it to the raw code of a page.
    What I’d like to do though is add it as a widget. When I do it shows Title and Content but not the price. Anybody have an idea how to make that happen.
    @jon Harmon, thanks for your code, unfortunately it doesn’t work in a widget either.

    #2643

    itwd.ian
    Participant

    Found it, forgot to add global $post; to the loop

    $loop = new WP_Query( $args ); 
       if ( $loop->have_posts() ) :
       while( $loop->have_posts() ) : $loop->the_post();
     global $post;?>
Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘BirchPress Scheduler’ is closed to new topics and replies.

Comments are closed.