twork/query 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

twork/query

Composer 安装命令:

composer require twork/query

包简介

A WP_Query wrapper.

README 文档

README

A WordPress WP_Query wrapper.

Installation

  • composer require twork/query

Example Usage:

use Twork\Query\Query;

$query = new Query('custom-post');

$query->author('Jim')
    ->category('tech')
    ->postsPerPage(20);

foreach ($query as $postId) {
    the_title();
}

In the above example, a query is created for custom-post post types, where the author is Jim, and the category is tech, with a maximum of 20 posts per page.

Alternatively, $query->fetch() can be used, which returns a generator that wraps the WP loop. It will yield either null, or an object, if a class is supplied as an argument.

use Twork\Query\Query;

$query = new Query();

foreach ($query->fetch() as $null) {
    the_title();
}
<?php

class Post {
    protected $id;

    public function __construct() {
        $this->id = get_the_ID();
    }

    public function getId() {
        return $this->id;
    }
}

use Twork\Query\Query;

$query = new Query();

foreach ($query->fetch(Post::class) as $post) {
    echo $post->getId();
}

Arguments that aren't available as methods can be added using addArg, shown in the example below.

$query = new Query('custom-post');

$query->addArg('author_name', 'Jim');

统计信息

  • 总下载量: 157
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固