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-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
*/
@MjHead
MjHead / form-custom-hook.php
Created September 19, 2021 08:07
JetFormBuilder. Example of custom hook with API request and redirect.
<?php
/**
* 'api-request' - is a customm hook name
*/
add_action( 'jet-form-builder/custom-action/api-request', function( $request, $action_handler ) {
$post_id = ! empty( $request['inserted_post_id'] ) ? $request['inserted_post_id'] : false;
if ( ! $post_id ) {
return;
<?php
/**
* Callback will be applied for each field of each CCT item in the REST API response
* cct_slug - change this with your actual CCT slug
* _cct_field_name - change this with your actual field name
*/
add_filter( 'jet-engine/custom-content-types/rest-api/filters/cct_slug', function( $filters ) {
$filters['_cct_field_name'] = 'my_cct_column_filter_callback';
return $filters;
} );
@MjHead
MjHead / search-min-by-non-empty.php
Created March 31, 2021 10:48
JetEngine, Dynamic Functions - search min value only by non-empty meta-fields
<?php
add_filter( 'jet-engine/dynamic-functions/final-query', function( $query, $function_data ) {
$data_source = ! empty( $function_data['data_source'] ) ? $function_data['data_source'] : false;
$source = ! empty( $data_source['source'] ) ? $data_source['source'] : 'post_meta';
$field_name = ! empty( $data['field_name'] ) ? $data['field_name'] : false;
if ( 'meta_value' === $source ) {
$query = preg_replace( '/;$/', 'AND `meta_value` != \'\';', $query );
@MjHead
MjHead / jet-form-builder-shortcode.php
Last active December 6, 2024 21:44
Form shortcode for JetFormBuilder
<?php
add_shortcode( 'my_jet_form', 'my_jet_form_shortcode' );
function my_jet_form_shortcode( $atts = array() ) {
$atts = shortcode_atts( array(
'id' => false,
'submit_type' => 'reload', // or ajax
'required_mark' => '*',
@MjHead
MjHead / jet-engine-cct-api.php
Last active November 19, 2024 16:30
API to interact with JetEngine CCT from directly PHP code
<?php
/**
* JetEngine CCT-related API functions to use in theme or plugin
*
* Theme usage - include get_theme_file_path( 'jet-engine-cct-api.php' );
* Plugin usage - include PLUGIN_PATH . 'path-to-file-inside-plugin/jet-engine-cct-api.php';
*/
/**