Powered By Blogger
Showing posts with label Post. Show all posts
Showing posts with label Post. Show all posts

Friday, October 28, 2016

add meta key or meta value or custom field for post

// Post offer box
add_action( 'add_meta_boxes', 'post_offer' );
function post_offer() {
   add_meta_box(
       'post_offer',
       __( 'Price', 'agrg' ),
       'post_offer_content',
       'post',
       'side',
       'high'
   );
}

function post_offer_content( $post ) {
wp_nonce_field( 'myplugin_meta_boxeee', 'myplugin_meta_box_nonceeee' );
$post_offer = get_post_meta( $post->ID, 'post_offer', true );

echo '<label for="post_offer"></label>';
echo '<input type="text" id="post_offer" name="post_offer" placeholder="'._e('Enter price here','agrg').'" value="';
echo $post_offer;
echo '">';

}

add_action( 'save_post', 'post_offer_save' );
function post_offer_save( $post_id ) {

global $post_offer;

if ( ! isset( $_POST['myplugin_meta_box_nonceeee'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonceeee'], 'myplugin_meta_boxeee' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}

if(isset($_POST["post_offer"]))
$post_offer = $_POST['post_offer'];
update_post_meta( $post_id, 'post_offer', $post_offer );

}

Add custom taxonomy type under post with form

REF : https://metabox.io/plugins/custom-taxonomy/


// Post Stock box
add_action( 'add_meta_boxes', 'post_stock' );
function post_stock() {
   add_meta_box(
       'post_stock',
       __( 'Stock', 'agrg' ),
       'post_stock_content',
       'post',
       'side',
       'high'
   );
}

function post_stock_content( $post ) {
wp_nonce_field( 'myplugin_meta_boxee', 'myplugin_meta_box_nonceee' );
$post_stock = get_post_meta( $post->ID, 'post_stock', true );

echo '<label for="post_stock"></label>';
echo '<input type="text" id="post_stock" name="post_stock" placeholder="'._e('Enter Stock here','agrg').'" value="';
echo $post_stock;
echo '">';

}

add_action( 'save_post', 'post_stock_save' );
function post_stock_save( $post_id ) {
global $post_stock;
if ( ! isset( $_POST['myplugin_meta_box_nonceee'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonceee'], 'myplugin_meta_boxee' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}

if(isset($_POST["post_stock"]))
$post_stock = $_POST['post_stock'];
update_post_meta( $post_id, 'post_stock', $post_stock );

}


$stock_labels = array(
            'name' => __( 'Stock', 'agrg' ),
            'singular_name' => __( 'Stock', 'agrg' ),
            'search_items' =>  __( 'Search Stocks', 'agrg' ),
            'popular_items' => __( 'Popular Stocks', 'agrg' ),
            'all_items' => __( 'All Stocks', 'agrg' ),
            'parent_item' => __( 'Parent Stock', 'agrg' ),
            'parent_item_colon' => __( 'Parent Stock:', 'agrg' ),
            'edit_item' => __( 'Edit Stock', 'agrg' ),
            'update_item' => __( 'Update Stock', 'agrg' ),
            'add_new_item' => __( 'Add New Stock', 'agrg' ),
            'new_item_name' => __( 'New Stock Name', 'agrg' ),
            'separate_items_with_commas' => __( 'Separate Stocks with commas', 'agrg' ),
            'add_or_remove_items' => __( 'Add or remove Stock', 'agrg' ),
            'choose_from_most_used' => __( 'Choose from the most used Stocks', 'agrg' ),
            'menu_name' => __( 'Stocks', 'agrg' )
        );
register_taxonomy("Stock",
array("post"),
array("hierarchical" => true,
'labels' => $stock_labels,
'show_ui' => true,
                'query_var' => true,
                'rewrite' => array('slug' => __('Stock', 'agrg'))
)
);


Add value in custom taxonomy pro-grammatically :

REF: https://codex.wordpress.org/Function_Reference/wp_insert_term

/* Location update while seller registration */
$saddress = sanitize_text_field($address);
//check location is exist
$loc_exist = term_exists( $saddress ); // array is returned if taxonomy is given

if (empty($loc_exist) ) {

$parent_term = term_exists( 'location' ); // array is returned if taxonomy is given
       $parent_term_id = $parent_term['term_id']; // get numeric term id
wp_insert_term(
 $saddress, // the term
 'location', // the taxonomy
 array(
   'description'=> 'A seller location.',
   'slug' => $saddress,
   'parent'=> $parent_term_id
                   )
    );
}


Tuesday, October 18, 2016

wishlist for post in wordpress

https://wordpress.org/plugins/gd-mylist/

https://wordpress.org/plugins/wp-favorite-posts

Friday, October 14, 2016

author based filter in all post in wp-admin in wordpress

function.php


function rudr_filter_by_the_author() {
 $params = array(
  'name' => 'author', // this is the "name" attribute for filter <select>
  'show_option_all' => 'All authors' // label for all authors (display posts without filter)
 );
 
 if ( isset($_GET['user']) )
  $params['selected'] = $_GET['user']; // choose selected user by $_GET variable
 
 wp_dropdown_users( $params ); // print the ready author list
}
 
add_action('restrict_manage_posts', 'rudr_filter_by_the_author');





https://rudrastyh.com/wordpress/filter-posts-by-author.html

Tuesday, September 27, 2016

wordpress get latest post from another website

1.Using Template
2. RSS widget


https://www.worldoweb.co.uk/2012/display-wordpress-posts-on-another-wp-blog

plugin:

https://wordpress.org/plugins/featured-images-for-rss-feeds/screenshots/

https://wordpress.org/plugins/wp-rss-aggregator/screenshots/



<?php
/**
 * Template Name: Blog  Page
 *
 * A Fully Operational maintenance Page
 *  WordPress
 */

get_header(); ?>
<div class="content_bgr website-maintenance-plan websiteplan-plan">
<div class="full_container_page_title">
<div class="container startNow">
<div class="row no_bm">
<?php
//replace with your URL
$rss = fetch_feed("http://demoinfolink.com/blog/");

if (!is_wp_error($rss)) :

$maxitems = $rss -> get_item_quantity(5); //gets latest 5 items This can be changed to suit your requirements
$rss_items = $rss -> get_items(0, $maxitems);
endif;

//grabs our post thumbnail image
function get_first_image_url($html) {
if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
return $matches[1];
}
}

//shortens description
function shorten($string, $length) {
$suffix = '&hellip;';
$short_desc = trim(str_replace(array("\r", "\n", "\t"), ' ', strip_tags($string)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?')
$suffix = '';
$desc .= $suffix;
return $desc;
}
?>
<!--start of displaying our feeds-->
<ul class="rss-items" id="wow-feed">
<?php
if ($maxitems == 0) echo '<li>No items.</li>';
else foreach ( $rss_items as $item ) :
?>
<li class="item">
<span class="rss-image">
<?php echo '<img width="200" src="' . get_first_image_url($item -> get_content()) . '"/>'; ?>
</span>
<span class="data">
<h5><a href='<?php echo esc_url($item -> get_permalink()); ?>' title='<?php echo esc_html($item -> get_title()); ?>'> <?php echo esc_html($item -> get_title()); ?></a></h5>
<span class="date-image">&nbsp;</span>
<small><?php echo $item -> get_date('F Y'); ?></small><!--This can be changed -->
<span class="comment-image">&nbsp;</spa






































































n>







































































<small><?php $comments = $item -> get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments'); ?><?php $number = $comments[0]['data']; ?>
<?php //checks and displays comment count
if ($number == '1')
{
echo $number . "&nbsp;" . "Comment";
}
else


























































{


























































echo $number . "&nbsp;" . "Comments";
}
?>
</small>
<p><?php echo shorten($item -> get_description(), '150'); ?></p>
</span>






































</li>






































<?php endforeach; ?>
</ul>

</div>
</div>
</div>
</div>

<?php get_footer(); ?>








add the following to your theme’sfunctions.php

Whilst functions.php is open check for or add the following