dsvbtgo639708 2017-05-24 09:39 采纳率: 0%
浏览 67
已采纳

postman chrome在从.net调用wordpress url时显示404错误

In a project, I have to show wp posts in website via .net. So, I created a php file in project root folder as 'latestnews.php'. When called from browser, everything is working fine and data is shown. But in postman though the data is shown status is coming as 404 not found.

How to solve this issue? Any help/suggestions are welcome. Url: http://109.74.4.178/worldwaterweek/latestnews.php?numberposts=5

latestnews.php

<?php
define('WP_USE_THEMES', false);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

$num = $_GET["numberposts"] ?: '10';

$posts = get_posts(array(
    'posts_per_page'   => $num,
    ));
$array = array();

foreach($posts as $val) {
    start_wp();
    $array[] = array(
            'id' => $val->ID,
            'title' => $val->post_title,
            'link' => get_permalink($val->ID),
            'publish_date' => $val->post_date,
            'content' => strip_tags($val->post_content),
            'image' => get_the_post_thumbnail_url($val->ID, 'full')
        );
}
echo json_encode($array);
?>
  • 写回答

2条回答 默认 最新

  • duanjue7508 2017-05-24 11:07
    关注

    Found the solution.

    Instead of loading wp-blog-header.php which in turn loads wp-load.php(loads wp library) and template-loader.php(loads wp templates), I added wp-load.php only.

    So, I guess wp template was creating the errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化