Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Shevchenko MjHead

  • Crocoblock
  • Ukraine
View GitHub Profile
@MjHead
MjHead / ajax-listing-url.php
Created Feb 2, 2022
JetEngine. Replace URL of ajax callback to get Listing items
View ajax-listing-url.php
<?php
add_filter( 'jet-engine/listings/ajax-listing-url', function( $url ) {
return esc_url( admin_url( 'admin-ajax.php' ) );
} );
@MjHead
MjHead / jet-engine-relations-update.php
Created Feb 2, 2022
JetEngine. Relations. Update related items
View jet-engine-relations-update.php
<?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
Created Feb 2, 2022
JetEngine. Get registered meta fields by given context - post type, taxonomy or user
View get-jet-engine-meta-fields.php
<?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 Jan 4, 2022
JetEngine Relations. Add custom fields into create new item popup. Add custom columns into related item table
View jet-engine-advanced-relations.php
<?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 Nov 26, 2021
Add own parameters into JetEngine Listing query args
View gist:ce5c649bbe725a49ecd6f623d49a1a2f
<?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 Nov 26, 2021
JetEngine. Custom macros registration with class
View include-class.php
<?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 Nov 11, 2021
JetSearch. Completely rewrite search query handler
View jet-search-rewrite.php
<?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 Nov 9, 2021
Register meta field to show in Rest API
View register-meta-field.php
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 Nov 9, 2021
JetEngine. Allows to update required CCT items on change posts in selected user meta data store
View update-cct.php
<?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
View jet-egine-customize-admin-filter-labels.php
<?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 );