Pages

May 16, 2014

WordPress interview questions and answers

What is the Difference Between Posts vs. Pages

Posts vs. Pages
* Posts are timely vs. Pages are timeless.
* Posts are social vs. Pages are NOT.
* Posts can be categorized vs. Pages are hierarchical.
* Posts are included in RSS feed vs. Pages are not.
* Pages have custom template feature vs. Posts do not.


How to store the post title in variable?

 $page_title = get_the_title($post->post_parent); 


How to Generates a random password of the specified length in WordPress?

 generate_random_password($len) ?> 


How to hide the Admin Bar in WordPress?

 add_filter('show_admin_bar', '__return_false'); 


How to get the postid in wordpress?
we can get the postid

  global $wp_query;

$postid = $wp_query->post->ID;
echo $postid;


How to get the post meta value in worpdress?
we can get the post meta value throw postid.
for example here post Custom Field name : comapny name

 get_post_meta($postid, 'Company name', true); 


How to check if the post has a Post Thumbnail assigned to it.


  if ( has_post_thumbnail() )  // check if the post has a Post Thumbnail assigned to it.
  { 
      the_post_thumbnail();
  }
 

How to get the wordpress featued image and how to change the image width and height.

we can get the featurd image wordpress function

 
the_post_thumbnail();//here we can get the wordpress featured image thumbnail

the_post_thumbnail( array(100,100) );     // here we can change the image size.

How to get the specified category post only in wordpress?

here we can get the all post in category id based.

<?php query_posts("cat=106
&& per_page=5");// here 106 is the category id  ?>

 <?php while ( have_posts() ) : the_post(); ?>

 <h3><?php the_title(); // here we can get the post title. this is the wordpress free defind function ?></h3>

 <?php  endwhile; ?>






What is the prefix of wordpress tables by default?
By default, wp_ is prefix of wordpress.

How can we backup or import our WordPress content from admin panel?
For import content from wordpress admin panel goes to
WordPress admin -> Tools -> Import

Can wordPress use cookies?
Yes, wordpress use cookies.WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users.

How to disable wordpress comment?
Look in to dashboard under Options –> Discussion. There is a checkbox there for "allow people to post comments on the article" Try unchecking that.

How many tables a default WordPress will have?
default wordpress will have 11 tables. They are-
1. wp_commentmeta
2. wp_comments
3. wp_links
4. wp_options
5. wp_postmeta
6. wp_posts
7. wp_terms
8. wp_term_relationships
9. wp_term_taxonomy
10.wp_usermeta
11.wp_users

How to install the wordpress 3.8.1?
Word press current is version 3.5.1. We can download the word press zip file in word press site. When ever we can download the word press zip file we can extract the file then after re name the file.
Step1:
Deploy the word press site in xampp.
Root folder: C:\xampp\htdocs\wordpress

Step2:
Open the browser Mozilla Firefox.
Create the database in mysql database
Open the phpmyadmin
Create the database name (word press)
Type an address (http://localhost/wordpress) into the URL bar.

Step3:
Click the Create a Configuration File button --->
Next we can click the let's go! Button
Then after we can write the Database Name, User Name, Password, Database Host, Table Prefix
Then after click the submit button.
Word press installation is completed.

What are the features of wordpress?
1. Simplicity,Make wordpress to manage easily that is its very easy to use.
2. Free open source ,its free to use wordpress.
3. Easy theme system,In wordpress we have thousand of good free theme to use.
4. Extends with plugins, we can extends the functionality of wordpress using thousands of free plugins or will create any plugin according to your requirements.
5. Community,WordPress has vibrant and supportive community.
6. Multilingual, wordpress is available on more than 70 languages.
7. Flexibility, with wordpress you will create any type of blog or website.
8. Comment, the built in comment system also make wordpress popular as you can comment your views on website.
9. Easy installation and upgrades.
10. Full standards compliance, Easy Importing,Cross-blog communication tools.
11. wordpress database tables list

wp_commentmeta : This table contains meta information about comments posted on a WordPress website. This table has four fields meta_id, comment_id, meta_key, and meta_value. Each meta_id is related to a comment_id. One example of comment meta information stored is the status of comment (approved, pending, trash, etc).

wp_comments : As the name suggests this table contains your WordPress comments. It contains comment author name, url, email, comment, etc.

wp_links : To manage blogrolls create by earlier versions of WordPress or the Link Manager plugin.

wp_options : This table contains most of your WordPress site wide settings such as: site url, admin email, default category, posts per page, time format, and much much more. The options table is also used by numerous WordPress plugins to store plugin settings.

wp_postmeta : This table contains meta information about your WordPress posts, pages, and custom post types. Example of post meta information would be which template to use to display a page, custom fields, etc. Some plugins would also use this table to store plugin data such as WordPress SEO information.

wp_posts : The name says posts but actually this table contains all post types or should we say content types. This table contains all your posts, pages, revisions, and custom post types.

wp_terms : WordPress has a powerful taxonomy system that allows you to organize your content. Individual taxonomy items are called terms and they are stored in this table. Example, your WordPress categories and tags are taxonomies, and each category and tag inside them is a term.

wp_term_relationships : This table manages relationship of WordPress post types with terms in wp_terms table. For example this is the table that helps WordPress determine post X is in Y category.

wp_term_taxonomy : This table defines taxonomies for terms defined in wp_terms table. For example if you have a term "WordPress Tutorials", then this table contains the data that says it is associated with a taxonomy categories. In short this table has the data that helps WordPress differentiate between which term is a category, which is a tag, etc.

wp_usermeta : Contains meta information about Users on your website.

wp_users : Contains User information like username, password, user email, etc.

How to get current user information in wordpress

  
  $current_user = wp_get_current_user();

  /**

  * @example Safe usage: $current_user = wp_get_current_user();

  * if ( !($current_user instanceof WP_User) )

  *     return;

  */

  echo 'Username: ' . $current_user->user_login . '
';

  echo 'User email: ' . $current_user->user_email . '
';

  echo 'User first name: ' . $current_user->user_firstname . '
';

  echo 'User last name: ' . $current_user->user_lastname . '
';

  echo 'User display name: ' . $current_user->display_name . '
';

  echo 'User ID: ' . $current_user->ID . '
';



Wordpress author related taxonomy posts

 

  
  global $post;

  $author_id=$post->post_author;

  $args = array(

  'post_type' => 'deals',

  'author'=> $author_id

  );


$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
//wp_reset_query();
endif;

?>

How to insert the values in wordpress database.?
insert query to use store the values in wordpress database.

  global $wpdb;

  $wpdb->insert($table_name,array('author_id' =>$author_id,'author_name' =>$author_name,'author_email'=>$author_email,'created_at'=>current_time('mysql', 1)),array('%d','%s','%s','%s'));

  

How to get the single value in wordpress database.?
using get_var
example:

  $table_name = $wpdb->prefix . "posts";

$post_content = $wpdb->get_var($wpdb->prepare( "SELECT post_content FROM $table_name WHERE post_status = %s",'publish'));
echo $post_content;

How to get posts from a specific category wordpress

  
$catquery = new WP_Query( 'cat=4&posts_per_page=10' );// cat = category

  //4=category id

  while($catquery->have_posts()) : $catquery->the_post();

  the_title();

  //content here

  ?>




  

How to write the short code in wordpress php file
using do_shortcode function inside of php echo tag
a very simple solution is to use the do_shortcode function inside a PHP echo tag.
for example
 do_shortcode("[shortcode]"); ?> 


short code is used in wordpress post or page and text box widget and php file.

How to display the wordpress breadcrumbs?

  function wordpress_breadcrumbs() {

$delimiter = '&raquo;';
$name = 'Home';
$currentBefore = '';
$currentAfter = '
';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '
';

global $post;
$home = get_bloginfo('url');
echo '' . $name . ' ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $currentBefore . 'Archive by category &#39;';
single_cat_title();
echo '&#39;' . $currentAfter;
} elseif ( is_day() ) {
echo '' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo '' . get_the_time('F') . ' ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_single() ) {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = 'ID) . '">' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . 'Search results for &#39;' . get_search_query() . '&#39;' . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . 'Posts tagged &#39;';
single_tag_title();
echo '&#39;' . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . 'Error 404' . $currentAfter;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '
';
}
}
?>

What is use of in_array() function in php ?
in_array used to checks if a value exists in an array
wordpress display post limite.

  'showposts'=>5,//display only 5 posts.

$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>5,//post limite
'ignore_sticky_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>

" rel="bookmark" title="
">
', '


'); ?>

&nbsp

endwhile;
}
}

WordPress display post content limit.
 
  

  $content = get_the_content();

  $content = strip_tags($content);

  echo substr($content, 0, 205);

?>


How to get the Excerpt post content in wordpress post?

here we can get the post Excerpt data.

 

  the_excerpt();

 

here rpc.php file data

  
require_once('wp-config.php'); ?>


$result = mysql_query("SELECT meta_value FROM wp_postmeta WHERE meta_key='address' LIMIT 5");


while ($row = mysql_fetch_array($result)) {

  echo '
  • list-style: none;">'.$row['meta_value'].'
  • '; } /* $selected = mysql_select_db("islasde",$dbhandle) or die("Could not select examples"); /*$query = $db->query("SELECT * FROM wp_postmeta LIMIT 5"); if($query) { // While there are results loop through them - fetching an Object (i like PHP5 btw!). while ($result = $query ->fetch_object()) { // Format the results, im using
  • for the list, you can change it. // The onClick function fills the textbox with the result. // YOU MUST CHANGE: $result->value to $result->your_colum echo '
  • meta_value.'\');">'.$result->meta_value.'
  • '; } } else { echo 'ERROR: There was a problem with the query.'; }*/ ?>

    No comments:

    Post a Comment

    Kindle Apps