Home News Contact Us Forum About Us Demos Products F.A.Q.
Shopping Cart
You currently have 0 items in your cart.


Recent Events
  • 31/12/2023 New Year SALE

    We are glad to announce New Year SALE. 25% discount for all our extensions. Use NY24 coupon code. Hurry up the discount is valid till 7 January.

  • 21/11/2023 BLACK FRIDAY 23 is coming

    BIG SALE, 35% discount for all our extensions. Use BF23 coupon code. Hurry up the discount is valid till 27 November.


2Checkout.com, Inc. is an authorized retailer of goods and services provided by ARI Soft. 2CheckOut




Follow us on twitter



Welcome, Guest
Please Login or Register.    Lost Password?

Get Quiz Image in template Page
(1 viewing) (1) Guest
"ARI Stream Quiz" WordPress plugin
Go to bottomPage: 1
TOPIC: Get Quiz Image in template Page
#65006
Get Quiz Image in template Page 5 Years, 1 Month ago Karma: 0
Hi, is there a way to get the Quiz Image in another page in my template?

I'm building a page that shows previous quizzes, so you can click any to open it in another page.
I would like to show the Quiz Image (the one that is stored in the DB as quiz_image_id in table wp_asq_quizzes) as a thumbnail for each of the quizzes in that page.
I know I can access the quiz image once the quiz loads, but in this page the quizzes are not loaded yet, only listed as posts with the following query:

Code:


$args_posts = array(
'posts_per_page'   => -1,
'order'            => 'DESC',
'post_type'        => 'aristreamquiz',
);  
$post_trivia = get_posts( $args_posts );
foreach ($post_trivia as $post_){

// HTML to print each quiz entry

}



So, can I get the quiz image having the post ID of said quiz?

Thanks!
The administrator has disabled public write access.
 
#65028
Re:Get Quiz Image in template Page 5 Years, 1 Month ago Karma: 748
Hello,

You can use the following code:

Code:


global $wpdb;
$attachments = $wpdb->get_results("SELECT post_id,quiz_image_id FROM {$wpdb->prefix}asq_quizzes", OBJECT_K);

$args_posts = array(
    'posts_per_page'   => -1,
    'order'            => 'DESC',
    'post_type'        => 'aristreamquiz',
);
$post_trivia = get_posts( $args_posts );
foreach ($post_trivia as $post_){
    $post_id = $post_->ID;
    $quiz_image_url = !empty( $attachments[$post_id]->quiz_image_id ) ? wp_get_attachment_url( $attachments[$post_id]->quiz_image_id ) : null;
    if ( ! is_null( $quiz_image_url ) ) {
        // specify some code to show quiz image
    }
}



Regards,
ARI Soft
The administrator has disabled public write access.
 
Go to topPage: 1