WordPress recent posts with content limit

<?php $query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 2 ) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID )); ?>
<div class=”col2″>
<div class=”article”>
<div class=”image”>
<a href=”<?php echo get_permalink($post->ID); ?>”>
<img src=”<?php echo $image ?>”>
</a>
</div>
<h2><a href=”<?php echo get_permalink($post->ID); ?>”><?php echo get_the_title(); ?></a></h2>
<p><?php $content = get_the_content(); echo mb_strimwidth($content, 0, 200, ‘…’);?></p>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

How to Add Google Search in a WordPress Site

  1. Go to Google Custom Search Engine and sign in using a Google account. Once there, click on New Search Engine and provide your WordPress website’s URL. The URL will also be used as your search engine’s name in your Google Custom Search Engine dashboard. Click on Create button to proceed to the next step.

gsearch1

 

2.  Please follow below image.

gsearch2

 

3.   Using Get code button you can find HTML code with java script you can place it in php page template.

Create post and update post meta from front end

<?php
$post_title = $_POST[‘post_title’];
$post_data = $_POST[‘post_data’];
$user_id = get_current_user_id();
$post_type = “gallery”;
$my_post = array(
  ‘post_title’    => $post_title,
  ‘post_content’  => $post_data,
  ‘post_status’   => ‘publish’,
  ‘post_author’   => $user_id,
  ‘post_type’ => $post_type
);
$post_id = wp_insert_post( $my_post );
update_post_meta($post_id, ‘_name’, $img);
?>