PHP code example of wp-kit / magic-meta

1. Go to this page and download the library: Download wp-kit/magic-meta library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wp-kit / magic-meta example snippets


composer 

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'
	];
	
}

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

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 ) );
		
	}
		 
	
}