Created
December 8, 2022 14:28
-
-
Save MjHead/2639c994277d517ac76f60126a0fdbb8 to your computer and use it in GitHub Desktop.
JetEngine. Dynamic Field callback to get link from combination of 2 meta fields - fro label and URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'jet-engine/listings/allowed-callbacks', 'my_je_callback_register' ); | |
function my_je_callback_register( $callbacks ) { | |
$callbacks['my_je_get_link_callback'] = 'Get link by meta fields'; | |
return $callbacks; | |
} | |
function my_je_get_link_callback() { | |
$label_field = 'status'; // Replace `status` with your meta field where link label is stored | |
$post_field = 'related-page'; // Replace `related-page` with your meta field where link post is stored | |
$label = jet_engine()->listings->data->get_meta( $label_field ); | |
$post_id = jet_engine()->listings->data->get_meta( $post_field ); | |
if ( ! $label || ! $post_id ) { | |
return; | |
} | |
return sprintf( '<a href="%1$s">%2$s</a>', get_permalink( $post_id ), $label ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment