Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jechazelle/c100e60f15c2ac46bf22742e6a78c950 to your computer and use it in GitHub Desktop.
Save jechazelle/c100e60f15c2ac46bf22742e6a78c950 to your computer and use it in GitHub Desktop.

Revisions

  1. @Crocoblock Crocoblock revised this gist Jun 29, 2023. 1 changed file with 23 additions and 2 deletions.
    25 changes: 23 additions & 2 deletions jet-engine-array-keys-macro.php
    Original file line number Diff line number Diff line change
    @@ -19,14 +19,24 @@ public function macros_args() {
    'type' => 'text',
    'default' => '',
    ),
    'to_regexp' => array(
    'label' => 'To REGEXP',
    'type' => 'select',
    'options' => array(
    'no' => 'No',
    'yes' => 'Yes',
    ),
    'default' => '',
    ),
    );
    }

    public function macros_callback( $args = array() ) {

    $object = $this->get_macros_object();

    $meta_key = ! empty( $args['meta_key'] ) ? $args['meta_key'] : null;
    $meta_key = ! empty( $args['meta_key'] ) ? $args['meta_key'] : null;
    $to_regexp = ! empty( $args['to_regexp'] ) ? $args['to_regexp'] : 'no';

    if ( ! $meta_key ) {
    return;
    @@ -38,7 +48,18 @@ public function macros_callback( $args = array() ) {
    return;
    }

    return array_keys( $meta );
    $result = array_keys( $meta );

    $delimiter = ',';

    if ( $to_regexp === 'yes' ) {
    $result = array_map( function( $item ) {
    return sprintf( '"%s"', $item );
    }, $result );
    $delimiter = '|';
    }

    return implode( $delimiter, $result );
    }
    }

  2. @Crocoblock Crocoblock created this gist Jun 29, 2023.
    47 changes: 47 additions & 0 deletions jet-engine-array-keys-macro.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?php

    add_action( 'jet-engine/register-macros', function(){

    class Current_Meta_Array_Keys extends \Jet_Engine_Base_Macros {

    public function macros_tag() {
    return 'get_array_keys';
    }

    public function macros_name() {
    return 'Array keys';
    }

    public function macros_args() {
    return array(
    'meta_key' => array(
    'label' => 'Meta key',
    'type' => 'text',
    'default' => '',
    ),
    );
    }

    public function macros_callback( $args = array() ) {

    $object = $this->get_macros_object();

    $meta_key = ! empty( $args['meta_key'] ) ? $args['meta_key'] : null;

    if ( ! $meta_key ) {
    return;
    }

    $meta = jet_engine()->listings->macros->get_current_meta( $field_value, $meta_key );

    if ( ! is_array( $meta ) ) {
    return;
    }

    return array_keys( $meta );
    }
    }

    new Current_Meta_Array_Keys();

    } );