wp-kit/magic-meta 问题修复 & 功能扩展

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

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

wp-kit/magic-meta

最新稳定版本:1.0.1

Composer 安装命令:

composer require wp-kit/magic-meta

包简介

A wp-kit component that handles Eloquent appending and querying of PostMeta

README 文档

README

This is a wp-kit component that handles Eloquent appending and querying of PostMeta.

When using Eloquent, wouldn't it be great if we could append PostMeta to the Model just as Wordpress does natively? And wouldn't be great to query data based on meta_query and tax_query parameters? This is exactly what wp-kit/magic-meta handles.

Installation

If you're using Themosis, install via Composer in the root of your Themosis installation, otherwise install in your Composer driven theme folder:

composer require "wp-kit/magic-meta"

Usage

Model

wp-kit/magic-meta comes with two traits, so all you need to do is include these in your model.

Based on drewjbartlett/wordpress-eloquent you can the Post model provided and use the IsMagic trait.

wp-kit/magic-meta relies on a ::getMeta method on the Model to return the meta_value, this is exactly what drewjbartlett/wordpress-eloquent provides.

namespace Theme\Models;

use WPEloquent\Model\Post;
use WPKit\MagicMeta\Traits\IsMagic;
use WPKit\MagicMeta\Traits\TransformsQuery;

class SomePostType extends Post {
	
	use IsMagic;
	use TransformsQuery;

	protected $magic_meta = [
		'_some_meta_key' => 'appended_key',
		'_location' => 'location'
	];
	
}

Query

Parameters

You can use ::transformQuery Query Scope on Illuminate\Database\Query\Builder to check for any of the following parameters. We also allow the query to check for any magic meta at root level of the parameters:

[
	's' => '',
	'meta_query' => [],
	'tax_query' => [],
	'appended_key' => 'something', // queries PostMeta key '_some_meta_key'
	'location' => 'london' // queries PostMeta key '_location'
]

Using transformQuery

namespace App\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use App\Models\SomePostType;

class SomePostTypeController extends Controller {
	
	public function index(Request $request) {
	
		return response()->json( SomePostType::select( 'posts.*' )->type( 'some_type' )->transformQuery( $request ) );
		
	}
		 
	
}

To Do

  • Make transformQuery agnostic to Request parameters, using Collection instead in case users are using jsonapi standard etc.

Get Involved

To learn more about how to use wp-kit check out the docs:

View the Docs

Any help is appreciated. The project is open-source and we encourage you to participate. You can contribute to the project in multiple ways by:

  • Reporting a bug issue
  • Suggesting features
  • Sending a pull request with code fix or feature
  • Following the project on GitHub
  • Sharing the project around your community

For details about contributing to the framework, please check the contribution guide.

Requirements

Wordpress 4+

PHP 5.6+

License

wp-kit/magic-meta is open-sourced software licensed under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-15