Tuesday, 19 January 2021

 118.codeigniter left join

$this->db->select('u.*,o.*');
        $this->db->from('tb_end_users as u');
        $this->db->join('tb_organizations as o''o.org_id = u.org_id','left');
        $this->db->where('u.euser_pk_id'$dpno);       
        $query=$this->db->get()->result();
        //print_r($this->db->last_query());  //to print query
        return $query;

Sunday, 17 January 2021

 117.ajax delete using modal in codeigniter

<a class="btn btn-default org_del_<?php  echo $r->org_id;?>" href="#"  id="<?php  echo $r->org_id;?>" onclick="deleteorg(<?php  echo $r->org_id;?>)">Delete</a>


before footer

<!-- delete modal -->
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
            
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
                </div>
            
                <div class="modal-body">
                    <p>You are about to delete one track, this procedure is irreversible.</p>
                    <p>Do you want to proceed?</p>
                    <p class="debug-url"></p>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-danger btn-ok" onclick="confirmdelete()">Delete</a>
                </div>
            </div>
        </div>
    </div>
<!-- end delete modal -->


js
function deleteorg(id){
$('#confirm-delete').modal('show');

$(".btn-ok").click(function(){

   $.ajax({         
      url: "<?php echo base_url(); ?>" + "User/org_del_ajax",
      data : {org_id:id},
      dataType: 'json',
      type: 'POST',      

      error: function() {
         alert('Something is wrong');
      },
      success: function (data) {
          jQuery('.org_'+id).remove();
          $('#confirm-delete').modal('hide');
            },
   });

});

}


controller
    public function org_del_ajax()
    {
        
    $orgid=$this->input->post('org_id');

    $result=$this->db->delete('tb_organizations'array('org_id' => $orgid));

    echo json_encode($result);
    
    }

Monday, 14 December 2020

115. How to create custom post type in wordpress?

 // Our custom post type function

function create_posttype() {
 
    register_post_type( 'movies',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'Movies' ),
                'singular_name' => __( 'Movie' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'movies'),
            'show_in_rest' => true,
 
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

114.How to Display wordpress category name with the related posts?

<?php
$categories = get_terms( array( 'taxonomy' => 'category' ) );
foreach( $categories as $cat ) :
    $posts = new WP_Query( array(
        'post_type'     => 'dt_portfolio',
        'showposts'     => -1,
        'tax_query'     => array(
                               array(
                                   'taxonomy' => 'category',
                                   'terms'    => array( $cat->term_id ),
                                   'field'   => 'term_id'
                               )

                          )
    ) ); ?>

    <h3><?php echo $cat->name; ?></h3>

    <ul>
        <?php while( $posts->have_posts() ) : $posts->the_post(); ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
        <?php endwhile; wp_reset_postdata(); ?>
    </ul>
 

<?php endforeach; ?>  

Wednesday, 9 December 2020

113.how to create custom post type and meta field in wordpress?

  function create_posttype() {


    register_post_type'about',
    // CPT Options
    array(
      'labels' => array(
       'name' => __'About' ),
       'singular_name' => __'About' )
       
      ),
     // 'supports' => array('title', 'editor', 'thumbnail'),
      'public' => true,
      'has_archive' => false,
      'rewrite' => array('slug' => 'about'),
     )
    );
   
    }
    // Hooking up our function to theme setup
    add_action'init''create_posttype' );


    add_theme_support('post-thumbnails');
    add_post_type_support'about''thumbnail' );


    function add_description_meta_boxes() {
      add_meta_box("about_description_meta""Description""add_description_meta_box""about""normal""low");
    }
    
    function add_description_meta_box()
    {
      global $post;
      $custom = get_post_custom$post->ID );
     
      ?>
      <style>.width99 {width:99%;}</style>
      <p>
        <label>Description:</label><br />
        <textarea rows="5" name="description" class="width99"><?= @$custom["description"][0?></textarea>
      </p>
    
      <?php
    }
    
    function save_description_custom_fields(){
      global $post;
     
      if ( $post )
      {
        update_post_meta($post->ID"description", @$_POST["description"]);
      }
    }
    add_action'admin_init''add_description_meta_boxes' );
    add_action'save_post''save_description_custom_fields' );
    

Sunday, 23 August 2020

112.wordpress pagination

 <?php 


global $wp_query;  
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$datanew WP_Query(array(
    'post_type'=>'portfolios'// your post type name
    'posts_per_page' => 2// post per page
    'paged' => $paged,
));

if($data->have_posts()) :
    while($data->have_posts())  : $data->the_post();
        echo  the_title();
    endwhile;

    $total_pages = $data->max_num_pages;

    if ($total_pages > 1){

        $current_page = max(1get_query_var('paged'));

        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
        ));
    }
    ?>    
<?php else :?>
<h3><?php _e('404 Error&#58; Not Found'''); ?></h3>
<?php endif?>
<?php wp_reset_postdata();?>