Dig deeper into WordPress is a presentation made for Web Designers Meetup in Cairo taken place on 17th Dec 2012.
Signup at WPMonkeys.com to get notified when awesome new WordPress related content is published.
How to Remove Document Management Hurdles with X-Docs?
Dig Deeper into WordPress - WD Meetup Cairo
1. Web Designers Meetup Cairo - 17th November 2012
Dig Deeper into
WordPress
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
2. Why?
Have you ever thought
over 70-million websites out
there are using WordPress
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
3.
4. flexi
WordPress main feature is
bility
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
5.
6. Custom Post Types
Custom Meta Boxes
Custom Taxonomies
Advanced Queries
Custom Admin Panels/Options
Plugin API
Hooks, Actions and Filters
Customizable Advanced User Capabilities
+ many more....
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
8. Custom Meta Boxes
<?php add_meta_box( $id, $title, $callback,
$post_type, $context, $priority,
$callback_args ); ?>
<?php
/*
Define
the
custom
box
*/
add_action(
'add_meta_boxes',
'myplugin_add_custom_box'
);
/*
Do
something
with
the
data
entered
*/
add_action(
'save_post',
'myplugin_save_postdata'
);
/*
Adds
a
box
to
the
main
column
on
the
Post
and
Page
edit
screens
*/
function
myplugin_add_custom_box()
{
add_meta_box(
'myplugin_sectionid',
__(
'My
Post
Section
Title',
'myplugin_textdomain'
),
'myplugin_inner_custom_box',
'post'
);
}
/*
Prints
the
box
content
*/
function
myplugin_inner_custom_box(
$post
)
{
//
Use
nonce
for
verification
wp_nonce_field(
plugin_basename(
__FILE__
),
'myplugin_noncename'
);
//
The
actual
fields
for
data
entry
echo
'<label
for="myplugin_new_field">';
_e("Description
for
this
field",
'myplugin_textdomain'
);
echo
'</label>
';
echo
'<input
type="text"
id="myplugin_new_field"
name="myplugin_new_field"
value="whatever"
size="25"
/>';
}
..........
http://codex.wordpress.org/Function_Reference/add_meta_box
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
9. Custom Meta Boxes (cont.)
/*
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;
if
(
!wp_verify_nonce(
$_POST['myplugin_noncename'],
plugin_basename(
__FILE__
)
)
)
return;
//if
saving
in
a
custom
table,
get
post_ID
$post_ID
=
$_POST['post_ID'];
$mydata
=
$_POST['myplugin_new_field'];
//
Do
something
with
$mydata
//
probably
using
add_post_meta(),
update_post_meta(),
or
//
a
custom
table
(see
Further
Reading
section
below)
}
?>
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
12. Advanced Queries
<?php $the_query = new WP_Query( $args ); ?>
WP_Query is a class defined in wp-includes/query.php that deals with the intricacies of a posts
(or pages) request to a WordPress blog. The wp-blog-header.php (or the WP class in Version 2.0)
gives the $wp_query object information defining the current request, and then $wp_query
determines what type of query it's dealing with (possibly a category archive, dated archive,
feed, or search), and fetches the requested posts. It retains a lot of information on the
request, which can be pulled at a later date.
<?php
$args=
array(
.
.
);
$query=
new
WP_Query($args);
//
Loop
while($query-‐>have_posts()):
$query-‐>next_post();
$id
=
$query-‐>post-‐>ID;
echo
'<li>';
echo
get_the_title($id);
echo
'</li>';
endwhile;
?>
http://codex.wordpress.org/Class_Reference/WP_Query
(C) 2012 Mohamed Mosaad. All Copyrights Reserved
14. Advanced Queries (cont.)
<?php $wpdb->get_results( MYSQLQuery ); ?>
The $wpdb object can be used to read data from any table in the WordPress database, not just the standard
tables that WordPress creates.
$wpdb-‐>query(
$wpdb-‐>prepare(
"
DELETE
FROM
$wpdb-‐>postmeta
WHERE
post_id
=
%d
AND
meta_key
=
%s
",
13,
'gargle'
)
);
or
$wpdb-‐>query(
"
UPDATE
$wpdb-‐>posts
SET
post_parent
=
7
WHERE
ID
=
15
AND
post_status
=
'static'
"
);
http://codex.wordpress.org/Class_Reference/wpdb
(C) 2012 Mohamed Mosaad. All Copyrights Reserved