Pages

Showing posts with label fetch. Show all posts
Showing posts with label fetch. Show all posts

Monday, May 6, 2013

Social Engine 4-Get values from a table

//gets a table called engine4_authorization_permissions

$permissionTable=Engine_Api_()->getDbTable('permissions','authorization');

$permissionSelect=$permissionTable->select()->where('level_id'=?,$userlevel)->where('type'=>'usercommit');

$fetchdata=$permissionTable->fetchrow($permissionSelect);

$fetchdatas=$permissionTable->fetchrows($permissionSelect);
//To get attribute from row

echo $fetchdata->attribute_name

foreach($fetchdatas as $fetchdata)
{
     echo $fetchdata->attribute_name;
}

Social Engine 4-Fetching and displaying a menu from backend

1. Create a menu from admin backend by going to Layout->Menu Editor from menu

2. Now go to database and in table "engine4_core_menus" find the entry for your menu and give the same name under "name" field(if already not there)

3. Now in controller to assign the menu to a view variable use

 $this->view->navigation=Engine_Api::_()->getApi('menus','core')->getNavigation('credit_main');  

where 'credit_main' is the 'name' of your menu from table "engine4_core_menus"

To render menu in view use


 echo $this->navigation()->menu()->setContainer($this->navigation)->render();  



Friday, May 3, 2013

Social Engine 4-Get avtar of user

$user_id=Engine_Api::()_->user->getviewer->getIdentity();

$userinfo=Engine_Api::_()->user()->getUser($user_id);

$photo_id=$user_info['photo_id'];


//Fetches table Engine4_storage_files

$filesTable=Engine_APi::_()->getDbtable('files','storage');

$adapter=Engine_Db_Table::getDefaultAdapter();

$filesTableName=$filesTable->info('name');

$query=Engine_Db_Table::getDefaultAdapter()->select("storage_path")->from($statsTableName)->where("field_id=?",$photo_id)->limit(1);

$result=$query->query()->fetch();

$result['storage_path'] //has the path to your photo


Thursday, November 8, 2012

Wordpress get posts on basis of name,category,tag

Since we have post name involved here long with category and tag we need to use custom query here which will provide us to search specific posts which contain special text in name and will belong to a particular category and will contain a tag as per requirements

Here is the custom query

I used a get in my search form with normal request parameters

 if (!(empty($_GET['section'])) || !(empty($_GET['article']))) {  
       global $wpdb, $post, $paged, $max_num_pages, $current_date;  
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  
       $post_per_page = intval(get_query_var('posts_per_page'));  
       $offset = ($paged - 1) * $post_per_page;  
       $val = $_GET['s'];  
       $cat = $_GET['category'];  
       $tag = $_GET['tag'];  
 $querystr = "  
   SELECT DISTINCT $wpdb->posts.*  
   FROM $wpdb->posts  
   LEFT JOIN $wpdb->postmeta wpostmeta ON ($wpdb->posts.ID = wpostmeta.post_id)  
   LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)  
   LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)  
     WHERE  
     $wpdb->posts.post_type = 'post'  
     AND $wpdb->posts.post_status='publish'";  
 //Tags and categories were like dropdowns so each time either "0" for no select or tag_id or //category_id or both were sent via GET as url params  
       if($tag > 0 && $cat > 0)  
       {  
         $querystr = $querystr . " AND ($wpdb->posts.post_title like '%$val%' AND ($wpdb->term_taxonomy.taxonomy = 'post_tag'  
       AND $wpdb->term_taxonomy.term_id IN($tag))) OR ($wpdb->posts.post_title like '%$val%' AND ($wpdb->term_taxonomy.taxonomy = 'category'  
       AND $wpdb->term_taxonomy.term_id IN($cat)))";  
       }  
       elseif ($tag > 0) {  
         $querystr = $querystr ." AND $wpdb->posts.post_title like '%$val%' AND ($wpdb->term_taxonomy.taxonomy = 'post_tag'  
       AND $wpdb->term_taxonomy.term_id IN($tag))";  
       }  
       elseif ($cat > 0) {  
               $querystr = $querystr . " AND $wpdb->posts.post_title like '%$val%' AND ($wpdb->term_taxonomy.taxonomy = 'category'  
         AND $wpdb->term_taxonomy.term_id IN($cat))";  
          }  
       $pageposts = $wpdb->get_results($querystr, OBJECT);  
       $querystr = $querystr . " LIMIT " . $offset . ", " . $post_per_page . "; ";  
       $sql_posts_total = $wpdb->get_var("SELECT FOUND_ROWS();");  
       $max_num_pages = ceil($sql_posts_total / $post_per_page);  

 //And can use pagination as
  <?php if ($wp_query->max_num_pages > 1) : ?>  
           <nav id="<?php echo $nav_id; ?>">  
             <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&larr;</span> Older posts', 'old')); ?></div>  
             <div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&rarr;</span>', 'next')); ?></div>  
           </nav>  
   <?php endif; ?>   


This is one way out...

Other way out is to put this filter in your functions.php

 add_filter('posts_where','wpse_posts_where', 10, 2 );  
 function wpse_posts_where( $where, &$wp_query )  
 {  
   global $wpdb;  
   if ( $wpse_title = $wp_query->get( 'wpse_title' ) ) {  
     $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $wpse_title ) ) . '%\'';  
   }  
   return $where;  
 }  


and then make a call to

 <?php if(!(empty($_GET['category'])) || !(empty($_GET['tag'])))  
 {  
   $val=$_GET['s'];  
   $cat=$_GET['category'];  
   $tag=$_GET['tag'];  
      global $query_string;  
      $qstr= $query_string."wpse_title=$val";  
      $args['wpse_title']=$val;  
      if($cat>0)  
      {  
           $args['category__and']=$cat;  
           $qstr=$qstr."&cat=$cat";  
      }  
      if ($tag>0)  
   {  
           $args['tag__in'] = $tag;  
           $qstr=$qstr."&tag=$tag";  
   }  
      query_posts($args);  
      query_posts($qstr);  
 ?>  


They both work how ever in later case youcan either make via name and category or name and tag

If you try to search via name category and tag you will end up getting a response which contains all the posts of that category..so I preffered using a custom query as it suited me