Skip to content

Instantly share code, notes, and snippets.

View MjHead's full-sized avatar

Andrew Shevchenko MjHead

  • Crocoblock
  • Ukraine
View GitHub Profile
@MjHead
MjHead / jet-engine-relations-update.php
Created February 2, 2022 09:27
JetEngine. Relations. Update related items
<?php
/**
* Update related item from form action/notification
*
* @param array $args [description]
* @return [type] [description]
*/
function my_update_related_items( $args = array() ) {
$relation = ! empty( $args['relation'] ) ? $args['relation'] : false;
@MjHead
MjHead / get-jet-engine-meta-fields.php
Last active April 6, 2024 17:55
JetEngine. Get registered meta fields by given context - post type, taxonomy or user
<?php
/**
* Get fields for the given context and object
* Should be called on hook 'init' with priority 11 or later
*/
// Fields for Post post type
$post_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type', 'post' );
// Fields for Product post type
@MjHead
MjHead / jet-engine-advanced-relations.php
Last active March 9, 2024 17:32
JetEngine Relations. Add custom fields into create new item popup. Add custom columns into related item table
<?php
/**
* Adds custom fields into the insert new related item popup.
* Hook name - jet-engine/relations/types/posts/create-fields - depends on type of created item,
* for CPT it will be - jet-engine/relations/types/posts/create-fields
* for terms - jet-engine/relations/types/terms/create-fields
* for users - jet-engine/relations/types/mix/create-fields/users
*
* just replace 'jobs' in the example with your actual post type/taxonomy slug
@MjHead
MjHead / gist:ce5c649bbe725a49ecd6f623d49a1a2f
Created November 26, 2021 13:20
Add own parameters into JetEngine Listing query args
<?php
add_filter( 'jet-engine/listing/grid/posts-query-args', function( $args, $widget, $settings ) {
if ( 'custom-query' === $settings['_css_classes'] ) {
$args['meta_query'][] = array(
'relation' => 'OR',
0 => array(
'key' => 'submission-date',
@MjHead
MjHead / include-class.php
Created November 26, 2021 11:48
JetEngine. Custom macros registration with class
<?php
/**
* Note! Always include mcros file only on 'jet-engine/register-macros' hook - before base class is not avaialable,
* after - all macros already registered and you can't insert a new one.
*/
add_action( 'jet-engine/register-macros', function() {
require_once get_theme_file_path( 'macros.php' );
new My_JE_Macros();
} );
@MjHead
MjHead / jet-search-rewrite.php
Last active February 5, 2024 14:48
JetSearch. Completely rewrite search query handler
<?php
add_action( 'wp_ajax_jet_ajax_search', 'my_get_search_results', 0 );
add_action( 'wp_ajax_nopriv_jet_ajax_search', 'my_get_search_results', 0 );
function my_get_search_results() {
$request = $_GET['data'];
$search_query = urldecode( $request['value'] );
$per_page = ( int ) $request['limit_query_in_result_area'];
@MjHead
MjHead / register-meta-field.php
Last active November 9, 2021 18:23
Register meta field to show in Rest API
add_action( 'init', function() {
// replace your-post-type-slug and your-meta-field-name with your actual data
register_post_meta( 'your-post-type-slug', 'your-meta-field-name', array(
'single' => true,
'type' => 'string',
'default' => '',
'auth_callback' => '__return_true',
'show_in_rest' => true,
) );
@MjHead
MjHead / update-cct.php
Created November 9, 2021 12:57
JetEngine. Allows to update required CCT items on change posts in selected user meta data store
<?php
/**
* Allows to update required CCT items on change posts in selected user meta data store
*/
add_filter( 'jet-engine/data-stores/ajax-store-fragments', function( $fragments, $store ) {
// Replace 'quoted-list' with your actual Data Store slug
$my_store = 'quoted-list';
// Replace 'users_wishlist' with you actual CCT slug
<?php
/**
* Given example can be used to format timestamp into human-readable date, but the same logic can be used for any modifications
*/
add_filter( 'jet-engine/admin-filters/filter-label', function( $label, $filter ) {
if ( 'meta' === $filter['type'] && '__date' === $filter['meta_key'] ) {
$label = date_i18n( get_option( 'date_format' ), $label );
}
return $label;
}, 10, 2 );
@MjHead
MjHead / terms-in-stores.php
Last active October 19, 2021 08:16
Allow to use terms with Jet Engine Data Stores
<?php
/**
* 1. Add this code into the end of functions.php of your active theme without opening PHP tag;
* 2. Replace strings, metioned in the comments below, with your actual data.
*/
add_filter( 'jet-engine/data-stores/store-post-id', function( $post_id, $store ) {
/**
* Replace 'cookies-store' with your actual Data Store slug
*/