• I’m setting up a page that has testimonials from clients, and each testimonial will be a post, and categorized. I was thinking that each testimonial would get a unique tag name, and then I could query that tag name to pull it on to the page. The thing that confuses me is how would the user get the tag to show up in the query? I thought about custom fields, but even then I’m not sure what to put in my $args so that it can pull the tagged post onto the page.

    $testimonial_query = new WP_Query('$args');

    Any thoughts?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter get_username

    (@get_username)

    Maybe I’m not explaining this well enough. Most arguments are based on simple filters like post count, category names, etc. I’d like to create an argument that basically says, “user has tagged a post, so I’ll grab that unique post name and show the content.” I hope this helps.

    A different way to do it would be to set up a Category called “testimonial”. You can then post the testimonials under that category, and add the category to your menu.

    Thread Starter get_username

    (@get_username)

    Hey Kevin,

    Thanks for the response. I’m not sure that would work because every testimonial needs to have a unique identifier, and each page is going to have a different testimonial. Maybe I’m misunderstanding you.

    You are talking about posts and pages as if they are the same thing but they are quite different, so I guess I am having trouble understanding what you want. Do you have an example site that you are trying to emulate?

    Thread Starter get_username

    (@get_username)

    Nope, no example site, but you can look at the site I’m working on.
    https://burtcrismore.com/clients/goates/about.htm
    This is purely the html version, not WordPress. Look down near the bottom of the page and you’ll see the single testimonial.

    I’m definitely not talking about posts and pages as being the same. I have a page. That page has a testimonial. In there end, there will be many testimonials. Each testimonial will be a post. I will categorize each testimonial so that the testimonials can have their own page, and be viewed in different groupings based on their category.

    Now, for my unique case seen above in the link, I want to allow the user to choose one of those testimonials for each individual page. For example, about will have one, contact us will have another.

    I hope that makes sense. Thanks for trying to help out.

    Thread Starter get_username

    (@get_username)

    Here is my code that I was trying to use to query a custom post type.

    <?php
    // Query Testimonial
    $testimonial_query = new WP_Query('post_type=testimonial');
    while ( $testimonial_query->have_posts() ) : $testimonial_query->the_post();
    ?>
    <?php the_content(); ?>
    
    <?php
    endwhile;
    wp_reset_postdata();
    ?>

    I thought this might work, but I have no way of knowing what to put in the value field so that it grabs the post with the unique identifier.

    If you know the post why don’t you just grab the content and put it into your page content? I guess I’m a little puzzled on why you are doing a query for a single post.

    Try searching the plugins section for testimonials, there may be a plugin to do what you want.

    I’ll dig into the code a bit when I have time and get back to you if you haven’t solved it by then. What I do know is you need to do a query to get the id of the tag and then you will be able to get the post content for that tag.

    You can also access the tag through the permalink for the tag, which would let you put that tag’s posts onto a page that could be accessed through your menu. You do this by adding a custom menu link and use the tag permalink.

    Sorry I couldn’t be of more help.

    If you want a user to be able to pick a post which is a testimonial and have that testimonial on a page here is one way:

    Have the user input the title of the post in a Custom Options Page.

    Then on the page you are to put the testimonial :

    if (have_posts()) : while (have_posts()) : the_post();
    
        if(get_the_title() == "testimonial title") the_content();
    
    endwhile;
    endif;
    Thread Starter get_username

    (@get_username)

    Hey Kevin,

    Thanks for sticking with this. I appreciate it. I ended up trying some custom meta boxes, which I’ve built into the Page write panel. The problem is that I can’t pull this custom meta.

    Here’s my first attempt with a wp_query loop

    <?php
    $testimonial_query = new WP_Query(array('post_type=page'));
    while ( $testimonial_query->have_posts() ) : $testimonial_query->the_post();
    ?>
    
    <p>"<?php $key_1_values = get_post_meta($post->ID, 'dbt_textarea'); ?>"</p>
    <h6><?php $key_2_values = get_post_meta($post->ID, 'dbt_text'); ?></h6>
    
    <?php
    endwhile;
    wp_reset_postdata();
    ?>

    I then tried the standard loop

    <?php
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <p><?php $key_1_values = get_post_meta($post->ID, 'dbt_textarea'); ?></p>
    <h6><?php $key_2_values = get_post_meta($post->ID, 'dbt_text'); ?></h6>
    
    <?php
    endwhile;
    endif;
    ?>

    I’m not sure why it’s not posting, but I figured having meta box on the page would be more intuitive for the client(user). Thoughts if this is a good approach, and if so, why the meta boxes aren’t showing content on the live page?

    I found this in the forum archives, tested it and it works.
    Make a post with a predefined tag, in the example I used tag1.

    <?php
          // The Query
          $the_query = new WP_Query( 'tag=tag1' );
          // The Loop
          while ( $the_query->have_posts() ) : $the_query->the_post();
               echo '<p>';
               the_title();
               the_content();
               echo '</p>';
           endwhile;
           // Reset Post Data
    	wp_reset_postdata();
    ?>
    Thread Starter get_username

    (@get_username)

    Thanks, Kevin. I haven’t had a chance to test it yet, but I do appreciate your efforts in finding this solution.

    Thanks,
    Burt

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How do you query a specific tag name?’ is closed to new replies.