function display_guest_author_shortcode() {
// Get the current post's ID
global $tdb_state_single;
$post_id = $tdb_state_single->post_id->__invoke();
// Check if the custom field 'guest_author' exists
$guest_author = get_post_meta($post_id, 'guest_author_name', true);
// Display the custom field value if it exists, otherwise show 'Staff'
$author_name = esc_html(!empty($guest_author) ? $guest_author : 'Staff');
$html = '<div class="td_block_wrap tdb_single_author td-pb-border-top td_block_template_1 tdb-post-meta" style="display:inline-block;font-family:Rubik!important;font-size: 13px!important;line-height: 1!important;font-weight: 400!important;text-transform: capitalize!important;padding-right:10px !important;margin-bottom:16px;color:#444;font-family:\'Open Sans\',\'Open Sans Regular\',sans-serif;font-size:11px;font-weight:400;clear:none;vertical-align:middle;line-height:1">
<div class="tdb-block-inner td-fix-index" style="display:flex;align-items:center"><div class="tdb-author-name-wrap" style="display:flex;align-items:baseline"><span class="tdb-author-by" style="margin-right:3px;font-family:Rubik!important;font-size:13px!important;line-height:1!important;font-weight:400!important;text-transform:capitalize!important">By</span> ' . $author_name . '</div></div></div>';
return $html;
}
// Register the shortcode
add_shortcode('display_guest_author_byline', 'display_guest_author_shortcode');
Then we do simple [display_guest_author_byline]
Goal was to replace the Author byline widget with something that will read a custom field (Guest Author) because none of the existing plugins seem to play nice with Newspaper theme. Simply publishing a custom field also didn’t work because we wanted some logic about showing ‘Staff’ when no Guest Author was there.
I used both Column Text and Text with Title options. This works nicely and saves once. However, every time I reload the TD Composer I get an error:
Errors at columns elements: 19(models) : 20(dom). The model does not match the content Current state has involved an issue. You could try an UNDO operation (CTRL+Z / CTRL+SHIFT+Z)
The shortcode I put in behaves like a normal shortcode and simply returns some html output.
If I remove the shortcode, everything goes back to working fine. For some reason having it execute a shortcode is causing this error.
I’m a developer, I’m asking what API/function calls work to get the ID of the post being rendered within the context of an external shortcode executing on a cloud template.
get_the_ID() returns the ID of the single template page. How does one get the ID of the page being rendered by the single template page?
Sorry, my question wasn’t clear.
I’m running custom code, inside a shortcode I put on the template.
So I added [my_shortcode] to single cloud template.
[my_shortcode] when it executes needs the ID of the post being rendered. But when I call the WordPress function get_the_ID() it returns the ID of the single cloud template instead. Which means I can’t get the proper data to manipulate and display.
How can I programmatically get the ID of the post with code executing in this context?
I did paste them. I didnt paste them on the forum because they are thousands of lines. But I copied them exactly in my code and still get this error.
I’m trying to get this working, I made a custom plugin following the documentation (https://forum.tagdiv.com/the-plugin-method/)
I copied the code for flex block 4 from td_config_blocks and put it into the plugin
//hook used to add or modify items via Api
add_action( 'tdc_loaded' , function() { //add the api code inside this function
td_api_block::add( 'td_flex_block_4_custom',
array(
'map_in_visual_composer' => false,
'map_in_td_composer' => true,
"name" => 'Flex Block 4 Custom',
"base" => 'td_flex_block_4_custom',
"class" => 'td_flex_block_4',
"controls" => "full",
"category" => 'Blocks',
'tdc_category' => 'Blocks',
'icon' => 'icon-pagebuilder-td_flex_block_4',
'file' => TDC_PATH_LEGACY . '/includes/shortcodes/td_flex_block_4.php',
I copied all the ‘tdc_style_params’ ‘tdc_start_values’ ‘params’ as well but don’t want to paste them here as they are very large.
I changed the parameters that seemed to need changing, by adding _custom ad the end of them. But kept all the code the same.
When I activate my plugin and try to load it in TD Composer it doesn’t load.
tdcJobManager.addJob - Error callback - textStatus: error errorThrown:
js_files_for_wp_admin.min.js?ver=e12b81d6cbdf467845997a891495df2cx:42 jobRequest {shortcode: '[td_flex_block_4_custom modules_category="image" m…xcerpt1="" show_excerpt2="none" hide_audio="yes"]', columns: 2, jobId: 1, postId: '40247', replyHtml: ''}
tdcJobManager.addJob - ERROR: 500 server error
I see in the logs this:
Fatal error: Uncaught Error: Class 'td_flex_block_4_custom' not found
in public_html/wp-content/plugins/td-composer/legacy/common/wp_booster/td_global_blocks.php on line 33
Any help getting this working would be appreciated.
-
This reply was modified 2 years by
wordpressive.
Thank you. Is it possible for you to show me where in the code Flex Block 4 was added/created, so I could copy/modify that code? I assume it uses this same API? I want to use it as an example to follow.
Where can I find the code for Flex Block 4, if I wanted to modify it? Or are there any hooks available?
Recreating it in custom module misses a lot of the features I can’t seem to replicate. Like using ajax categories dropdown on the header.
Is there a way to add more than 1 tag to Flex Block 4?
The unique articles fixed it, I didn’t see this option until I updated to the latest version. I was 2 minor versions behind apparently.
Thank you