Skip to content

Instantly share code, notes, and snippets.

View MjHead's full-sized avatar

Andrew Shevchenko MjHead

  • Crocoblock
  • Ukraine
View GitHub Profile
<?php
add_shortcode( 'post_terms', function( $atts = array() ) {
$atts = shortcode_atts( array(
'tax' => '',
'tax_2' => '',
'tax_3' => '',
), $atts, 'post_terms' );
@MjHead
MjHead / get-cct-from-code.php
Last active October 5, 2020 07:50
Get Custom Content Type items from the code
<?php
/**
This function should be called on the 'init' hook with priority 11 or later,
if not custom content type instances will not be registered yet
Available operators:
=
!=
@MjHead
MjHead / cct-admin-column-callback.php
Created October 6, 2020 13:31
Add custom callback for the CCT admin column
<?php
/*
form_submissions - replace this with your actual CCT slug
cct_single_post_id - replace this with your actual field name
*/
add_filter( 'jet-engine/custom-content-types/admin-columns', function( $columns, $factory ) {
if ( 'form_submissions' === $factory->get_arg( 'slug' ) && isset( $columns['cct_single_post_id'] ) ) {
$columns['cct_single_post_id']['_cb'] = 'my_get_edit_post_link';
}
<?php
add_action( 'edit_user_profile', 'my_user_likes' );
add_action( 'show_user_profile', 'my_user_likes' );
function my_user_likes( $user ) {
// user-meta-store you need to replace with your actual Data Store slug
$liked = get_user_meta( $user->ID, 'je_data_store_user-meta-store', true );
echo '<h2>User Likes</h2>';
@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';
*/
/**
@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 / 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 );
<?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 / 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;
@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
*/