WPBakery Grid builder get post content - wordpress

I am trying to show full content of Post in WpBakerys Grid builder
I can only add Post Excerpt but i would like to add full content not summary.I saw that I can add custom field but don't know Field key name of Post Content.
In short how can i show full post content instead of Excerpt?

You can add a custom shortcode to the Grid Builder:
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' );
function my_module_add_grid_shortcodes( $shortcodes ) {
$shortcodes['vc_post_content'] = array(
'name' => __( 'Post Content', 'my-text-domain' ),
'base' => 'vc_post_content',
'category' => __( 'Content', 'my-text-domain' ),
'description' => __( 'Show current post content', 'my-text-domain' ),
'post_type' => Vc_Grid_Item_Editor::postType(),
);
return $shortcodes;
}
// output function
add_shortcode( 'vc_post_content', 'vc_post_content_render' );
function vc_post_content_render() {
return '<p>{{ post_data:post_content }}</p>'; // usage of template variable post_data with argument "post_content"
}
Source: https://kb.wpbakery.com/docs/developers-how-tos/adding-custom-shortcode-to-grid-builder/#AddingCustomShortcodetoGridBuilder-Templatevariablesusage

Related

Remove title & add new button from a custom post type - wordpress

Need a solution to remove the "Title" and "Add new" button from a post type without jQuery.
You can disable the add new capabilities while passing the parameter in the register post type.
The parameter is :
create_posts' => false
Assuming you have the code like below :
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'capabilities' => array(
'create_posts' => false
)
);
register_post_type( 'custom_post_type', $args );
In order to remove the title I'm not sure if that is possible,
one solutions would be hiding using css
Best way to remove the title is to use the function remove_post_type_support().
remove_post_type_support('custom_post_type', 'title');
You can add this to your functions.php file by calling it via the init hook.
add_action( 'init', 'remove_custom_post_support' );
function remove_custom_post_support() {
remove_post_type_support( 'custom_post_type', 'title' );
}

Trying to create dynamic widget area using post ID

In functions.php I added this code.
function page_widget_init( $post_id = 0 ) { {
register_sidebar( array(
'name' => __( 'Page Widgets', 'seven_theme' ),
'id' => 'page-widgets-' . $post_id,
'description' => __( 'To display Layers Widgets in front page, before your posts, after header.', 'seven_theme' ),
) );
}
add_action( 'widgets_init', 'page_widget_init', 100 );
First how to get post id in functions.php register_sidebar $post_id
Now going to page template which i created using page.php, called Blog Template
Call this widget in this page.
dynamic_sidebar( 'page-widgets-' . $post->ID );
My idea is to create unique widget content using post ID.

Display custom post type category taxonomy

I have a custom post type and a taxonomy which allows the user to select which category the post is in.
Here is my custom taxonomy:
add_action( 'init', 'create_talcat_taxonomy', 0);
function create_Talcat_taxonomy()
{
register_taxonomy ( 'Talcat', 'artist', array( 'hierarchical' =>
true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true )
);
}
On my homepage I am querying the post_type=artist , which works fine and brings in my artist posts. However how can I print/display the name of the category that post belongs to and then link to that category page?
Similar to the_categories WordPress has function the_taxonomies to display custom taxonomies assigned to post type.
http://codex.wordpress.org/Function_Reference/the_taxonomies
Example:
<?php the_taxonomies('before=<ul>&after=</ul>'); ?>
<?php
$args = array(
//default to current post
'post' => 0,
'before' => '<p class=\"meta\">',
//this is the default
'sep' => ' ',
'after' => '<p class=\"meta\">',
//this is the default
'template' => '%s: %l.'
);
the_taxonomies($args);
?>
I have managed to find a clean and simple way to achieve printing the taxonomy term assigned to the post with the following:
<?php the_terms( $post->ID, 'TAXONOMY NAME', ' ', ' / ' ); ?>
Using term retrieves the terms associated with the given object(s), in the supplied taxonomies.
Here is a link to the codex with examples and further detail.

Update wordpress post from front-end (using acf)

I am making front end admin for users to add/edit their posts. I already made post add form and it works, but edit form doesnt work.
functions.php
function add_new_post( $post_id )
{
if( $post_id == 'new' ) {
// Create a new post
$post = array(
'post_title' => $_POST["fields"]['field_52c810cb44c7a'],
'post_category' => array(4),
'post_status' => 'draft',
'post_type' => 'post'
);
// insert the post
$post_id = wp_insert_post( $post );
return $post_id;
}
else {
return $post_id;
}
}add_filter('acf/pre_save_post' , 'add_new_post' );
index.php
<div id="updateform-<?php the_ID(); ?>" class="collapse">
<?php
echo get_the_ID();
$args = array(
'post_id' => get_the_ID(), // post id to get field groups from and save data to
'field_groups' => array(31), // this will find the field groups for this post (post ID's of the acf post objects)
'form' => true, // set this to false to prevent the <form> tag from being created
'form_attributes' => array( // attributes will be added to the form element
'id' => 'post',
'class' => '',
'action' => get_permalink( get_the_ID() ),
'method' => 'post',
),
'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
'html_before_fields' => '', // html inside form before fields
'html_after_fields' => '', // html inside form after fields
'submit_value' => 'Update', // value for submit field
'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
);
acf_form( $args );
?>
</div>
For saving posts you should use save_post not pre_save_post.
Basically pre_save_post is used for new posts.
Use this below add_filter('save_post' , 'add_new_post');
I created plugins for that:
Forms actions
https://wordpress.org/plugins/forms-actions/
Add actions to yours ACF forms.
ACF Frontend display
https://wordpress.org/plugins/acf-frontend-display/
Display your ACF form on frontend
If by some chance you happen to be using Elementor Page Builder, you can do this by installing Advanced Widgets for Elementor. It comes with an ACF Form widget that you can just drag & drop anywhere into your site and configure your form through the UI (no coding required).

WordPress widget area disapper

I am working on a WordPress site. While adding some widget in widget section, I got some issue.
I add some thing in primary widget area and right widget area, and when I refresh the widget page my added content got disappear although it is displaying in the front-end of WordPress,but now I am not able to edit that content from admin section.
My code is as follows:
add_filter( 'sidebars_widgets', 'disable_sidebar_L_widgets' );
function disable_sidebar_L_widgets( $sidebars_widgets ) {
if (!is_front_page() ) $sidebars_widgets['primary-widget-area'] = false;
return $sidebars_widgets; }
add_filter( 'sidebars_widgets', 'disable_sidebar_R_widgets' );
function disable_sidebar_R_widgets( $sidebars_widgets ) {
if (!is_front_page() ) $sidebars_widgets['right-widget-area'] = false;
return $sidebars_widgets;
}
Edit functions.php and locate for register_sidebar function. Change the id to small caps example :
register_sidebar( array(
'name' => __( 'Main Sidebar', ),
'id' => 'sidebar-1',
'before_widget' => '',
'after_widget' => "",
'before_title' => '',
'after_title' => '',
) );

Resources