Pages

Saturday, December 22, 2012

Getting Tags,Categories by Post Type Wordpress/get_terms shows empty array

Recently I faced an Issue of getting tags of a Custom Postype created by Me and I solved it as follows
I registered a taxonomy for the same as follows

For Tags
register_taxonomy(ad_tag,
            array('my_cust_posttype'),
            array('hierarchical' => false,
                  'labels' => array(
                        'name' => __( 'Ad Tags', 'appthemes'),
                        'singular_name' => __( 'Ad Tag', 'appthemes'),
                        'search_items' =>  __( 'Search Ad Tags', 'appthemes'),
                        'all_items' => __( 'All Ad Tags', 'appthemes'),
                        'parent_item' => __( 'Parent Ad Tag', 'appthemes'),
                        'parent_item_colon' => __( 'Parent Ad Tag:', 'appthemes'),
                        'edit_item' => __( 'Edit Ad Tag', 'appthemes'),
                        'update_item' => __( 'Update Ad Tag', 'appthemes'),
                        'add_new_item' => __( 'Add New Ad Tag', 'appthemes'),
                        'new_item_name' => __( 'New Ad Tag Name', 'appthemes')
                    ),
                    'show_ui' => true,
                    'query_var' => true,
                    'update_count_callback' => '_update_post_term_count',
                    'rewrite' => array( 'slug' => $tag_tax_base_url, 'with_front' => false ),
            )
    );

For Categories
    register_taxonomy( APP_TAX_CAT,
            array(APP_POST_TYPE),
            array('hierarchical' => true,
                  'labels' => array(
                        'name' => __( 'Ad Categories', 'appthemes'),
                        'singular_name' => __( 'Ad Category', 'appthemes'),
                        'search_items' =>  __( 'Search Ad Categories', 'appthemes'),
                        'all_items' => __( 'All Ad Categories', 'appthemes'),
                        'parent_item' => __( 'Parent Ad Category', 'appthemes'),
                        'parent_item_colon' => __( 'Parent Ad Category:', 'appthemes'),
                        'edit_item' => __( 'Edit Ad Category', 'appthemes'),
                        'update_item' => __( 'Update Ad Category', 'appthemes'),
                        'add_new_item' => __( 'Add New Ad Category', 'appthemes'),
                        'new_item_name' => __( 'New Ad Category Name', 'appthemes')
                    ),
                    'show_ui' => true,
                    'query_var' => true,
                    'update_count_callback' => '_update_post_term_count',
                    'rewrite' => array( 'slug' => $cat_tax_base_url, 'with_front' => false, 'hierarchical' => true ),
            )
    );

And Then I retrieved Tags for my custom post type as
$mylinks_tags = get_terms('ad_tag','orderby=name&hide_empty=0');

remember the parameter hide_empty if you are starting afresh you will get an empty array if this is not set to 0 by default this is 1 which means all empty terms will be hidden.Scratched my head for a couple of hours to figure this out

Saturday, December 15, 2012

Wordpress Theme Not Updating Or Cache Issue

Wordpress Theme Not Updating Or Cache Issue:

Sometimes we get a wordpress installation and have to work on the same.I recently faced this theme not updating issue when I had to customize the functionality of a Preinstalled theme by creating a child theme from the same.


If you installed WordPress yourself and you did not install a cache plugin then WordPress itself is not caching. If you are you using a preinstall then check the plugins to look for anything that could resemble a caching plugin. One of the better known one's is WP Super Cache for example.


Firefox Caching: Get latest page every time

Firefox Caching
Get latest page every time


Internet Explorer has a fantastic Web Cache option in Tools > Internet Options > Browsing History > Settings > called “Check for newer versions of Stored Pages:’. This option lets you override Internet Explorers smart caching option.
This is useful when you’re visiting websites that frequently have changing, dynamic data, but their meta tags or HTTP Content headers don’t tell your browser to get a new copy of the page every time. All you have to do is switch the setting to “Every time I visit the webpage“.
To access it in Firefox, simply enter this into your URL location box:
about:config
Then find the browser.cache.check_doc_frequency and change it to 1. This will force Firefox to check for a newer version of the page you’re viewing, regardless of the servers instructions, or Firefox’s default settings.
This is useful because by default Firefox is set at 3 which means that it will always used an old, cached version of the web page, unless the server specifically indicates a newer one is available. You never know if you’re getting the right stuff.
For reference, valid values for browser.cache.check_doc_frequency are:
0 – Check for a new version of a page once per session (a session starts when the first application window opens and ends when the last application window closes).
- Check for a new version every time a page is loaded.
2 – Never check for a new version – always load the page from cache.
3- Check for a new version when the page is out of date. (Default)




Friday, December 14, 2012

Remove Wordpress Toolbar/Panel from top

To remove wordpress toolbar/panel from top use the following code in functions.php of your template

add_filter( 'show_admin_bar', '__return_false' );
To remove the faint line, go into white.css, find the block:


#header {
 background-color:transparent;
 background-image:none;
 border-bottom:1px solid #E5E5E5;
}
and remove the line border-bottom:1px solid #E5E5E5;

Thursday, December 13, 2012

Buddypress-User registration is currently not allowed

Buddypress Error:

Buddypress Error:User Registration is currently not allowed on registration page is simple caused because Membership for anyone is disabled in wordpress.

To resolve this issue simple do 1 thing

In admin panel go to

Settings->General

and in front of Membership section check mark "Anyone can register Check box"

Tuesday, December 11, 2012

Oscommerce Add products to cart manually

In order to add products manually by Id or customize cart manually in OSCommerce

we need to first include the following file

require("includes/application_top.php")

What  this does is automatically includes the following class

require(DIR_WS_CLASSES . 'shopping_cart.php');(line 126)

and instantiates an object of class

if (!tep_session_is_registered('cart') || !is_object($cart)) {
    tep_session_register('cart');
    $cart = new shoppingCart; 
} 
or you can yourself include these files and create an object
But for any action in oscommerce I prefer to include application_top.php
If you are building up a new cart add
$cart->reset();
This will reset your cart which is only required if you are planning to add a new cart in my case I was sending all Items from another website to my oscommerce website so I decided to reset cart first

Now let us suppose we have item information in an array $items

foreach($items as $item)
{
       $attributes = isset($HTTP_POST_VARS['id']) ? $HTTP_POST_VARS['id'] : '';
       $cart->add_cart($item['id'],$item['quant'],$attributes);
      //In case cart is not empty and you want to add quantity to an item
      $cart->add_cart(
$item['id'], $cart->get_quantity('$item['id']')+1);
}

Then add the following lines
//Cleans any product with quantity zero
$cart->cleanup();
//Calculates the weight and total cost in all finalizes your cart
$cart->calculate();

That's All

Associate a file extension with a language in notepad++

Select Settings and then Style Configurator and you will get a window as follows


 Add a file type as shown above for example I have added ctp User extension to link cakephp ctp extension as a php file

Sunday, December 9, 2012

Hiding Controller from cakephp Url

In routes.php add the following code

  Router::connect('/*', array('controller' => 'Site', 'action' => 'display'));

What this does is each time you fire a url with "/parameter" it redirects to Site controller and display action

Now under site controller in display action add this

class SiteController extends AppController
{
    public $name="Site";
   
    public function display()
    {
        $path = func_get_args();
        //print_r($path);
        $count = count($path);
        if (!$count)
        {
             $this->redirect('/');
        }
        else
        {
            $this->render(implode('/', $path));
        }
    }
}

Wednesday, November 28, 2012

Configure Eclipse for Android Dev/Tools not found Error

Just started up with my first development with Android here is the link to how to setup Android ADT Package in Eclipse...
 
http://developer.android.com/sdk/eclipse-adt.html#installing
 
Here is the link for complete guide.
 
http://developer.android.com/sdk/installing.html#Installing
 
And if you are still getting an error like tools not found in android sdk in Eclipse
  
Run Android SDK Manager from start menu 
 
On the top you will see SDK Path

copy that path(you won't be able to copy it practically.I meant just take a note of that path)

run eclipse 
 
it will show an error that tools not found in a given directory

click on window menu select preferences

select Android from the list on left hand side 
 
on the right hand side you will find "SDK Location". Copy that path next to that and Bingo issue resolved 

Indicating a value as decimal literal in C Sharp

A value such as 14.5 is taken as a double by default by C Sharp and which cannot be automatically typecasted in decimal.

So indicate its data type as decimal we append M at its back

for example

decimal variable= 14.5M

Sunday, November 25, 2012

PHP Fatal error: Class 'CTestCase' not found Yii

PHP Fatal error:  Class 'CTestCase' not found

Running the command from the folder where bootstarp.php for testcases resolves this issue

Try running the tests from \protected\tests

Installing PHP Unit and Selenium and configuring it on Netbeans IDE

Follow the following links and tutorials to install and configure both(wanted it to be a one stop tutorial).

Follow this to install PEAR
http://itfeast.blogspot.in/2012/11/installing-pear.html

Installing PHPUnit

http://pear.phpunit.de/

To  Install Selenium 

Make sure you have Pear and phpunit installed

Then to install Selenium
Use this command
pear install Testing_Selenium-beta

To configure all this on Net-beans use this link
 http://netbeans.org/kb/docs/php/phpunit.html

Sunday, November 11, 2012

Adding php and phpunit to Windows default path

Adding php and phpunit to Windows default path

Open System in control panel=>Advance System Setting=>Envirnoment Variables=>

You will find a variable path in

Path

append to it your php directory..that's it

 Here is an image of the same...



Installing PHP Unit/Nothing to Upgrade error message

First of all we need to install PEAR as stated in my post

http://itfeast.blogspot.in/2012/11/installing-pear.html

Now that we have installed PEAR if success we will notice a PEAR folder in our php directory

also in our PHP directory will find a PEAR command line interface file

We need to place this a windows root path so that we can execute or files from everywhere for this refer

http://itfeast.blogspot.in/2012/11/adding-php-and-phpunit-to-windows.html


Now...

Installing PHP Unit

Fire the following command
pear channel-discover pear.phpunit.de
 
followed by
pear install phpunit/PHPUnit
 
wait for a few time depending on your internet speed phpunit will get downloaded and installed
 
If you get something similar to this you are done with phpunit installation 
 
C:\wamp\bin\php\php5.4.3>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

C:\wamp\bin\php\php5.4.3>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony.com
Did not download optional dependencies: phpunit/PHP_Invoker, use --alldeps to
wnload automatically
phpunit/PHPUnit requires package "channel://pear.symfony.com/Yaml" (version >=
.1.0)
phpunit/PHPUnit can optionally use package "phpunit/PHP_Invoker" (version >= 1
.0)
phpunit/PHPUnit_MockObject can optionally use PHP extension "soap"
downloading File_Iterator-1.3.3.tgz ...
Starting to download File_Iterator-1.3.3.tgz (5,152 bytes)
.....done: 5,152 bytes
downloading Text_Template-1.1.4.tgz ...
Starting to download Text_Template-1.1.4.tgz (3,701 bytes)
...done: 3,701 bytes
downloading PHP_CodeCoverage-1.2.6.tgz ...
Starting to download PHP_CodeCoverage-1.2.6.tgz (155,960 bytes)
...done: 155,960 bytes
downloading PHP_Timer-1.0.4.tgz ...
Starting to download PHP_Timer-1.0.4.tgz (3,694 bytes)
...done: 3,694 bytes
downloading PHPUnit_MockObject-1.2.2.tgz ...
Starting to download PHPUnit_MockObject-1.2.2.tgz (20,347 bytes)
...done: 20,347 bytes
downloading PHP_TokenStream-1.1.5.tgz ...
Starting to download PHP_TokenStream-1.1.5.tgz (9,859 bytes)
...done: 9,859 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.3.3
install ok: channel://pear.phpunit.de/Text_Template-1.1.4
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.4
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.1.5
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.2.6
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.2.2

C:\wamp\bin\php\php5.4.3> 
 

Now there are times we get an error while updating phpunit "Unabable to update PHP UNIT"

Message comes "Nothing to upgrade"

Follow following steps to upgrade phpunit in such cases

pear clear -cache

pear install -a-- phpunit/phpunit

and phpunit will upgrade successfully

Selecting random row from mysql database

Here is a simple query to select random row from a phpmysql database

Select * from `users` ORDER BY rand() limit 0,1

where users is the name of my table

Installing PEAR

PEAR is a very good package which contains pre defined built classes for various functionality which prevents one to re invent the wheel

I use mostly for TDD Test driven development which needs phpUnit which requires PEAR

Installing PEAR is very simple all you have to do is install php or a vanilla package like wamp, mamp, xampp, lamp now

download the file

http://pear.php.net/go-pear.phar

and place it under your php folder I use Wamp vanilla package so I will place under C:\wamp\bin\php\php.version

Its a windows machine

Now open your command line interface(windows) or shell(linux) and navigate to directory of your php folder and execute

php go-pear.phar

Under windows Vista,7 or in some versions of linux you might get a permission denied message in such  cases you need to run command prompt under admin mode.

To do so in windows under start->all programs->accessories->(right click on command prompt and select run as administrator to get the things work out for you)

Thursday, November 8, 2012

Wordpress plugins posting form or data to another Page in plugin

Wordpress plugins posting form or data to another Page in plugin

 <form id="mikex-settings" action="<?php echo plugins_url('update.php', __FILE__) ?>">  
   <label>Search Text:</label> <input name="search" value="<?php echo $options['search'] ?>" type="text" /><br />  
   <label>Replace Text:</label> <input name="replace" value="<?php echo $options['replace'] ?>" type="text" /><br />  
   <label>Replace Color</label> <input name="replace-color" value="<?php echo $options['replace-color'] ?>" type="text" /><br />  
   <label>Toggle Color:</label> <input name="toggle" value="<?php echo $options['toggle'] ?>" type="text" /><br />  
   <input type="submit" value="Update" /><span class="update-status"></span>  
 </form>  


In this way we an call another page to show up completely of a plugin in case of searchboxes etc

Add Metaboxes and Metafields to your wordpress posts

Add Metaboxes and metafields to your wordpress posts


 add_action('add_meta_boxes','mypost_add_custom_box');  
 add_action('save_post','myplugin_save_postdata');  
 function mypost_add_custom_box() {  
   add_meta_box(  
     'myplugin_sectionid',  
     __('Post Type Selection','myplugin_textdomain'),  
     'myplugin_inner_custom_box',  
     'post'  
   );  
 }  
 function myplugin_inner_custom_box( $post ) {  
  wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );  
  // The actual fields for data entry  
  $scheckval=esc_attr(get_post_meta($post->ID,'slider_post',true));  
  $pcheckval=esc_attr(get_post_meta($post->ID,'popular_post',true));  
  if($scheckval=='on')  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_slider_field" name="myplugin_slider_field"/>';  
  echo '<label for="myplugin_slider_field">';  
     _e("Slider Post", 'myplugin_sdomain' );  
  echo '</label> ';  
  if($pcheckval=='on')  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field" checked="checked"/>';  
  else  
  echo '<input type="checkbox" id="myplugin_popular_field" name="myplugin_popular_field"/>';  
  echo '<label for="myplugin_popular_field">';  
     _e("Popular Post", 'myplugin_pdomain' );  
  echo '</label>';  
 }  
 /* When the post is saved, saves our custom data */  
 function myplugin_save_postdata( $post_id ) {  
  // verify if this is an auto save routine.  
  // If it is our form has not been submitted, so we dont want to do anything  
  if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )  
    return;  
  // verify this came from the our screen and with proper authorization,  
  // because save_post can be triggered at other times  
  if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )  
    return;  
  // Check permissions  
  if ( 'page' == $_POST['post_type'] )  
  {  
   if ( !current_user_can( 'edit_page', $post_id ) )  
     return;  
  }  
  else  
  {  
   if ( !current_user_can( 'edit_post', $post_id ) )  
     return;  
  }  
  // OK, we're authenticated: we need to find and save the data  
  if($_POST['myplugin_slider_field']=='on')  
  $smydata=$_POST['myplugin_slider_field'];  
  else  
  $smydata='off';  
  if($_POST['myplugin_popular_field']=='on')  
  $pmydata=$_POST['myplugin_popular_field'];  
  else  
  $pmydata='off';  
  update_post_meta($post_id,'slider_post',$smydata);  
  update_post_meta($post_id,'popular_post',$pmydata);  
 }