承接 wp-kit/magic-meta 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wp-kit/magic-meta

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固