首页 > 解决方案 > wordpress php代码使用post_content调用显示来自数组内部的db图像

问题描述

我正在尝试通过 php 编码使用 wordpress 从 mysql db 获取图像。我能够获取 url 路径但不显示图像。我想显示图像以及描述和标题,但我得到了没有格式化的组合结果。

 foreach ( $database_results as $result ) {
          
  $car_model = array(
      
        'post_name'=>wp_strip_all_tags($result->Color),
        'post_content' => wp_strip_all_tags($result->title.' '. $result->descriptions.''."<?php echo '<img src='.$result->image.'/>' ?>"),
        
        
        'post_title' => wp_strip_all_tags( $result->Brand  . ' ' . $result->Model . ' ' . $result->Km ),
        '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 );
}

这是我的sql数据库表

describe wp_garage;

场地 类型 无效的 钥匙 默认 额外的
ID 整数 是的 无效的
图片 斑点 是的 无效的
文本 是的 无效的
模型 文本 是的 无效的
标题 文本 是的 无效的
说明 中文本 是的 无效的
颜色 文本 是的 无效的
公里 整数 是的 无效的
insert into wp_garage value("5644","https://static.toiimg.com/thumb/msid-79720359,width-1070,height-580,imgsize-78661,resizemode-75,overlay-toi_sw,pt-32,y_pad-40/photo.jpg","p","p","my name","wordpress","green","12");

Query OK, 1 row affected (0.01 sec) 在此处输入图像描述

标签: phpmysqlwordpressplugins

解决方案


推荐阅读