【问题标题】:How can I return all posts from a certain month using the WordPress REST api如何使用 WordPress REST api 返回某个月份的所有帖子
【发布时间】:2015-08-27 10:32:23
【问题描述】:

我正在使用 REST api 在 WordPress 中构建一个简单的 Angular 博客应用程序,到目前为止,我有一个选择下拉列表来按类别过滤帖子,但我需要设置一个按月显示档案的选择。

我不确定如何创建 ng-repeat 以遍历有帖子的月份,然后如何按所选月份过滤帖子。

这就是我对类别的处理方式,首先 - 在控制器中:

$http.get('/wp-json/taxonomies/category/terms').success(function(data){
    $scope.categories = data;
});

然后在视图中:

<label for="categories">Categories:</label>
<select name="categories" ng-model="filterCat">
    <option value="">Select month</option>
    <option ng-repeat="category in categories" ng-bind-html="category.name" value="{{category.name}}"></option>
</select>

我需要做的是查询 JSON(日期)并仅检索选择下拉列表的月份(可能还有年份),然后过滤这些帖子。

非常感谢。

【问题讨论】:

    标签: php angularjs wordpress api rest


    【解决方案1】:

    我认为它现在有效!这是基于 Plunkr 其他人发布的使用 Angular 按日期过滤:

    $scope.selectedMonthFilter = function(element) {
        var d = new Date(element.date)
        if (!$scope.selectedMonth) return true;
        return d.getMonth() == $scope.selectedMonth;
    }
    

    其余部分与链接的 Plunkr 相同。

    【讨论】:

      猜你喜欢
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 2020-11-23
      • 2018-02-17
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      相关资源
      最近更新 更多