How to display a image thumbnail for custom post type programattically
-
I am currently working on a word press custom post, where I fetch content from mysql database and programatically create the post using wp_insert_post.After doing this title and description is fetched and displayed as expected. However the image is not being displayed instead url alone is getting printed.
Please find my code related to the image display (I am not sure any other tags need to added).
‘post_content’ => wp_strip_all_tags($result->descriptions.”.$result->image ),
please find the full code related to fetching and display logic.
function techiepress_query_garage_table( $car_available_in_cpt_array ) { global $wpdb; $table_name = $wpdb->prefix . 'garage'; if ( NULL === $car_available_in_cpt_array || 0 === $car_available_in_cpt_array || '0' === $car_available_in_cpt_array || empty( $car_available_in_cpt_array ) ) { $results = $wpdb->get_results("SELECT * FROM $table_name"); return $results; } else { $ids = implode( ",", $car_available_in_cpt_array ); $sql = "SELECT * FROM $table_name WHERE id NOT IN ( $ids )"; $results = $wpdb->get_results( $sql ); return $results; } } function techiepress_insert_into_auto_cpt() { $car_available_in_cpt_array = techiepress_check_for_similar_meta_ids(); $database_results = techiepress_query_garage_table( $car_available_in_cpt_array ); if ( NULL === $database_results || 0 === $database_results || '0' === $database_results || empty( $database_results ) ) { return; } foreach ( $database_results as $result ) { $car_model = array( 'post_title' => wp_strip_all_tags( $result->Brand), 'post_content' => wp_strip_all_tags($result->descriptions.''.$result->image ), 'meta_input' => array( 'id' => $result->id, 'brand' => $result->Brand, 'model' => $result->Model, 'color' => $result->Color, 'km' => $result->Km, ), 'post_type' => 'auto', 'post_status' => 'publish', ); wp_insert_post( $car_model ); } }
- This topic was modified 4 years, 2 months ago by .
- This topic was modified 4 years, 2 months ago by .
- This topic was modified 4 years, 2 months ago by .
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to display a image thumbnail for custom post type programattically’ is closed to new replies.