How to display all testimonials on a single page via shortcode in wordpress?


Purangkapala

I created shortcode to display all testimonials on one page. I created custom post type to add each testimonial. Can anyone tell me how to display all testimonials on a single page. This code is used to create sshortcode below the code I mentioned :-

function fn_testimonials_block()
{
$args = array(
    'post_type'=> 'testimonials',
    'order'    => 'ASC'
    );              

$the_query = new WP_Query( $args );

$pages              = $the_query->posts;

//echo "<pre>";
//print_r($pages);
//echo "</pre>";

//exit;

$output = '';
$count = 1;

foreach($pages as $page) {

    //-----------------

    $author         = $page->post_title;
    $testimonial    = $page->post_content;
    $page_url       = get_page_link( $page->ID );
    $author_image   = get_the_post_thumbnail_url( $page->ID, 'thumbnail' );

    if ($count%2 == 1)
    {  
         $output .= '<div>';
    } 

    $output .= '<div>
              <p>'.$testimonial.'<br>
              <img src="'.$author_image .'"> <span>'.$author.', </span></p>
            </div>';

    if ($count%2 == 0) 
    {
        $output .= '</div>';
    }

    $count++;

}

if ($count%4 != 1){
    $output .= '</div>';
} 

return $output;
}
large pores

I think you have to pass the 'posts_per_page' key in the $args array . So your $args array looks like this

$args = array(
    'post_type'=> 'testimonials',
    'order'    => 'ASC',
    'posts_per_page' => '-1'
);

I'm not sure what $count variable you are using . I think you're trying to implement pagination logic there, but since your question is about showing all testimonials on a single page, I won't get into that part.

Making changes in $args will return all referral objects.

Related


How to get all tags as shortcode list from Wordpress page/post?

Adifaz At the end of every page and every post, I want to output the tags as a list of shortcodes. Unfortunately I don't know much about PHP, but someone who understands can surely correct me with the code below. Thank you in advance! <?php // functions.php |

How to get all tags as shortcode list from Wordpress page/post?

Adifaz At the end of every page and every post, I want to output the tags as a list of shortcodes. Unfortunately I don't know much about PHP, but someone who understands can surely correct me with the code below. Thank you in advance! <?php // functions.php |

How to get all tags as shortcode list from Wordpress page/post?

Adifaz At the end of every page and every post, I want to output the tags as a list of shortcodes. Unfortunately I don't know much about PHP, but someone who understands can surely correct me with the code below. Thank you in advance! <?php // functions.php |

How to get all tags as shortcode list from Wordpress page/post?

Adifaz At the end of every page and every post, I want to output the tags as a list of shortcodes. Unfortunately I don't know much about PHP, but someone who understands can surely correct me with the code below. Thank you in advance! <?php // functions.php |

How to display Wordpress CPT items in a single page

milad-ahmadi04 I define the client position type (Slug = Portfolio). After publishing a portfolio post and then clicking "View Post", the Not Found page will appear. This is my first question. I want that when the user clicks on a portfolio item, the item open

How to display Wordpress CPT items in a single page

milad-ahmadi04 I define the client position type (Slug = Portfolio). After publishing a portfolio post and then clicking "View Post", the Not Found page will appear. This is my first question. I want that when the user clicks on a portfolio item, the item open

How to call image via WordPress shortcode attribute?

Shahryal Kabir I'm developing a WordPress plugin for wordpress.org and this is my first plugin. I can't solve my own problem (I googled a lot and still can't find any solution). But maybe for some people, the solution to this problem is simple. So if you know

How to call image via WordPress shortcode attribute?

Shahryal Kabir I'm developing a WordPress plugin for wordpress.org and this is my first plugin. I can't solve my own problem (I googled a lot and still can't find any solution). But maybe for some people, the solution to this problem is simple. So if you know

How to display subfield (image) with shortcode in Wordpress?

Alexei Martinez These are the composition of custom fields: 1 set of footers 1.1 Group Col2 1.1.1 bbcimg (this is the picture ID) 1.1.2 bbc-rss (this is the RSS feed ID) I have the following code to display bbc-rss: <div class="col-md-3"> <?php

How to display subfield (image) with shortcode in Wordpress?

Alexei Martinez These are the composition of custom fields: 1 set of footers 1.1 Group Col2 1.1.1 bbcimg (this is the picture ID) 1.1.2 bbc-rss (this is the RSS feed ID) I have the following code to display bbc-rss: <div class="col-md-3"> <?php