标签: wp-api

在类库中注册休息路线不起作用

我在构建WP插件时遇到了两个问题,问题是我想使用WP Rest API并通过自己的端点对其进行扩展。

我正在使用类对象编写代码,我注册了add_action('rest_api_init'我遇到的问题是端点现在正在路由中显示。

这是初始化插件时的代码。

class ThorAdmin {

    public function __construct() {

        // Activation and deactivation hook.
        register_activation_hook(WP_PLUGIN_DIR . '/wp-thor-fcm/wp-thor-fcm.php',  array($this, 'thor_fcm_activate'));
        register_deactivation_hook( WP_PLUGIN_DIR . '/wp-thor-fcm/wp-thor-fcm.php',  array($this, 'thor_fcm_deactivate' ));

        // Admin Menu
        add_action('admin_menu', array($this, 'thor_admin_menu'));
        add_action('admin_init', array($this, 'thor_fcm_settings_init'));

        add_action('wpmu_new_blog',  array($this, 'thor_on_new_blog', 10, 6));      
        add_action('activate_blog',  array($this, 'thor_on_new_blog', 10, 6));

        add_action('admin_enqueue_scripts', array($this, 'thor_head') );            

        //The Following registers an api route with multiple parameters. 
        add_action('rest_api_init', array($this, 'add_thor_fcm_route'));

        add_filter('admin_footer_text', array($this, 'thor_fcm_admin_footer'));
    }
Run Code Online (Sandbox Code Playgroud)

这是我从add_action('rest_api_init',array($ this,'add_thor_fcm_route'))调用的函数;

/**
 * Registers the routes for all and single options …
Run Code Online (Sandbox Code Playgroud)

wordpress wp-api

3
推荐指数
1
解决办法
2461
查看次数

使用 API Rest 和 Angular 自定义 WordPress 登录

有没有办法使用 WordPress 和 Angular 的 API Rest 创建自定义登录。

\n\n

目前我正在使用 WP REST API - OAuth 1.0a 服务器插件,但我可以\xc2\xb4t 弄清楚如何做到这一点

\n\n

或者也许可以使用两种方法(基本身份验证和 OAuth)?

\n\n

我将不胜感激任何帮助

\n

wordpress wp-api angular

3
推荐指数
1
解决办法
4680
查看次数

WP API 获取帖子标签

尝试使用 wordpress API 获取帖子标签 - api 调用是 /wp-json/wp/v2/posts

ourHTMLString += '<i class="fa fa-tags">"' + postsData[i].tags + '"</i>';
Run Code Online (Sandbox Code Playgroud)

它正在返回这些值

"tags": [
        766,
        19,
        578
],
Run Code Online (Sandbox Code Playgroud)

我需要标签名称和href,不知道如何获得。我已经尝试过 postsData[i].wp:term[i].tag.name- 找不到解决方案。有什么帮助吗?谢谢

javascript tags wordpress wp-api wordpress-rest-api

3
推荐指数
1
解决办法
4846
查看次数

WP Rest API 获取精选图片

我正在构建一个相对简单的博客页面,它使用 WP Rest Api 和 AngularJs 在前端显示数据。

在我的主页上,我想返回标题,然后是特色图片,然后是摘录。我已经很好地提取了标题和摘录,似乎在 JSON 中,特色图像是媒体 ID。动态提取这些数据的最佳方法是什么?

我在互联网上看到了各种使用 PHP 函数的东西,但我认为最好的方法是在 angular 控制器中,只是寻找一些关于控制器究竟是什么的建议

列表视图 HTML

<ng-include src=" dir + '/form.html?v=2' "></ng-include>
<div class="row">
    <div class="col-sm-8 col-lg-10 col-lg-push-1 post">         
        <div class="row-fluid">
            <div class="col-sm-12">
                <article ng-repeat="post in posts" class="projects">
                    <a class="title" href="#/post/{{post.slug}}"><h2>{{post.title.rendered}}</h2></a>
                    <p ng-bind-html="post.excerpt.rendered | to_trusted"></p>
                </article>
            </div>
        </div>
    </div>
</div>  
Run Code Online (Sandbox Code Playgroud)

控制器

.controller('listPage',['$scope','Posts', function($scope,Posts){

    $scope.refreshPosts = function(){
        Posts.query(function(res){
            $scope.posts = res;
        });
    };
    $scope.refreshPosts();

    // CLEARFORMFUNCTION
    $scope.clear = function(){
        $scope.$root.openPost = false;
        jQuery('#save').modal('hide');
    };


    // SAVEMODALOPEN/COSE
    $scope.openSaveModal = function(){ …
Run Code Online (Sandbox Code Playgroud)

rest wordpress angularjs wp-api

2
推荐指数
1
解决办法
8741
查看次数

WordPress WP REST API按域限制请求

这似乎更明显.我使用WordPress来管理外部网站的内容.WordPress内容通过WP REST API显示,我将带有ajax和JS的内容显示到此远程站点.(例如https://example.com//wp-json/wp/v2/pages/23).一切都在SSL上,一切都很好.我怎样才能简单地做到这一点,这个ajax GET请求只允许来自某个域 - 远程站点?WP API仅用于显示数据.

php ajax rest wordpress wp-api

2
推荐指数
1
解决办法
687
查看次数

如何使用where子句进行WpGraphQL查询?

这很好

  query QryTopics {
    topics {
      nodes {
          name
          topicId
          count
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是我想要一个过滤的结果。我是graphql的新手,但是我在此集合上看到一个名为“ where”,“ first”,“ last”,“ after”等之后的参数……我该如何使用?它的类型是'RootTopicsTermArgs',可能是从我的架构自动生成的。它具有字段,其中之一是布尔值的“无子级”。我正在尝试做的是仅返回带有帖子标记的主题(Wordpress中的自定义分类法)。基本上,它阻止了我在客户端上执行此操作。

data.data.topics.nodes.filter(n => n.count !== null)
Run Code Online (Sandbox Code Playgroud)

谁能指导我一个在集合中使用where args的好例子?我已经尝试过我能想到的所有语法组合。包括

  topics(where:childless:true)
  topics(where: childless: 'true')
  topics(where: new RootTopicsTermArgs()) 
  etc... 
Run Code Online (Sandbox Code Playgroud)

显然,这些都是错误的。

wp-api graphql graphiql

2
推荐指数
1
解决办法
1227
查看次数

Nuxt 生成动态路由路径

我正在使用 wp-api 创建一个站点。我所有的页面都在里面: - pages -- _slug 如果我的页面 slug 是 site.com/about

- pages -- about Nuxt 会像这样生成 html。但是...如果我的路径是 site.com/company/about

我可以创建这条路线吗?

PS:我为此使用了 wordpress api。所以如果我的页面有父页面,路径是:site.com/parent/child

vue.js wp-api

2
推荐指数
1
解决办法
7595
查看次数

WordPress REST API-超过10个帖子

我搜索了此问题,并尝试了几种没有运气的解决方案。

我的主要路线在这里:https : //cnperformance.wpengine.com/wp-json/wp/v2/products?_embed

我安装了“ WP REST API过滤器参数”插件,以还原当REST API移至WordPress核心时删除的过滤器。

我试过了:https : //cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[per_page]=-1

https://cnperformance.wpengine.com/wp-json/wp/v2/products?_embed&?filter[posts_per_page]=-1

我也在functions.php中尝试过

add_filter( 'rest_endpoints', function( $endpoints ){
    if ( ! isset( $endpoints['/wp/v2/products'] ) ) {
        return $endpoints;
    }
    unset( $endpoints['/wp/v2/products'][0]['args']['per_page']['maximum'] );
    return $endpoints;
});
Run Code Online (Sandbox Code Playgroud)

参考在这里:https : //github.com/WP-API/WP-API/issues/2316

我已将posts_per_page的值设置为100,-1,没有区别。我还尝试仅添加参数'&posts_per_page = -1而不使用过滤器查询,但这也不起作用。任何帮助或见解,不胜感激!

wordpress custom-post-type wp-api wordpress-rest-api

2
推荐指数
1
解决办法
3263
查看次数

如何引用具有半冒号的对象

我正在使用AngularJS和WordPress Rest API.我正在发出一个返回对象的get请求.要获得特色图像,我必须使用'?embed'参数,该参数是另一个名为_embedded的对象.

问题是我希望在_embedded里面的对象叫做wp:featuredmedia.如果我在角度中这样引用它我会得到一个语法错误.

这是我的代码

$http.get(queries[0], {'cache': true}).
    then(function(response) {
        $scope.careers_title = strip(response.data.title.rendered);
        $scope.careers_content = strip(response.data.content.rendered);
        $scope.careers_feature_image = strip(response.data.featured_media);
        console.log(response.data._embedded);
    });
Run Code Online (Sandbox Code Playgroud)

console.log返回此信息

Object {author: Array[1], wp:featuredmedia: Array[1], wp:term: Array[2]}author: Array[1]wp:featuredmedia: Array[1]0: Object_links: Objectalt_text: ""author: 1date: "2016-04-25T09:33:52"id: 46link: "http://localhost:8888/rubis/wordpress/energy-efficiency/tp-roundall/"media_details: Objectmedia_type: "image"mime_type: "image/png"slug: "tp-roundall"source_url: "http://localhost:8888/rubis/wordpress/wp-content/uploads/2016/04/tp-roundall.png"title: Objecttype: "attachment"__proto__: Objectlength: 1__proto__: Array[0]wp:term: Array[2]__proto__: Object
Run Code Online (Sandbox Code Playgroud)

php wordpress json angularjs wp-api

1
推荐指数
1
解决办法
2577
查看次数