stefano mavilio

wordpress custom fields and taxonomy

http://netinial.com/blog/wordpress/get_post_meta_multiple-pagination-and-ordering

WordPress get_post_meta_multiple, Pagination and Ordering.

Dealing with wordpress.

Because of seo power of wordpress almost every my project I’m using wordpress.
According to me wordpress is single but powerful framework.

Maybe you already know about Custom Field Taxonomies in wordpress.
It was pretty simple Custom Field Filter plug in.

I use it lots of project that I manage.
And also I was pretty happy with this plug in.

But after that 1.4 version they changed their direction of Custom Field Taxonomies from custom fields to tags.

As Custom Field Taxonomies alternative I searched near all of web.

Found 3 function as alternative.

wordpress -> query_posts() was good function. But not supporting multiple filters.

I found get_post_meta_multiple function thanks to the Jamie.

and get_post_meta_multiple (modified version of first) thanks to the Matt

Matt’s function was almost near the function that I looking for. But it was not supporting Order by, Order as, and Pagination also some problems about null category.
You can see both pages people are asking about these, (me to :) )

I took some help from codes of Jignesh Patel he has also another code to Pagination but I do not like it. to complicated.

Lastly I modified all of them (spend two days on it)

Hope to helps someone.

usage

<?php
$aMetaDataList = array('type' => 'Flat', 'for' => 'Sale');
global $resultList;
    $szCategory = 'NULL'; // All Categories will be shown, $szCategory = '1,2,3'; Only from 1,2,3
    $ppp = 5; // Post per page.
    $metaKey = 'total_property_size'; // Metakey to order.
    $orderBy = 'desc'; // orderBy = 'asc'; for Ascending
    $orderType = 'numerical'; // Order as Numerical, $orderType = 'Aphabetical'; Leave Blank Alphabetical
    $resultList = get_post_meta_multiple( $aMetaDataList, 'post', $szCategory, $ppp, $metaKey, $orderBy, $orderType);
?>

function comes here.

<?php
function get_post_meta_multiple( $aMetaDataList = array(), $szType = 'post', $szCategory = NULL, $ppp, $metaKey, $orderBy, $orderType)
{
    /**
     * @author Modified by Deniz Netinial.com
     * @copyright deniz [at] porsuk dot net
     * to modify I spend 1 week on it.
     * If you like this modification just send me an e mail, with thanks. SQL_NO_CACHE
     */

    global $wpdb,$wp_query;
    $szQuerystr = "SELECT SQL_Calc_Found_Rows $wpdb->posts.* FROM $wpdb->posts ";

    if ( $szCategory != NULL AND is_string($szCategory) )
    {
    $szQuerystr .= " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) ";
    $szQuerystr .= " INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";
    }
    $szQuerystr .= " JOIN $wpdb->postmeta on ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ";

    if ( $szCategory != 'NULL' AND is_string($szCategory) )
    {
    $szQuerystr .= " 1=1 AND $wpdb->term_taxonomy.taxonomy = 'category' ";
    $szQuerystr .= " AND $wpdb->term_taxonomy.term_id IN(".$szCategory.")  AND ";
    }

    $szQuerystr .= " $wpdb->posts.post_type = '".$szType."' AND $wpdb->posts.post_status = 'publish'";

    if($metaKey){
    $szQuerystr .= " AND $wpdb->postmeta.meta_key = '".$metaKey."' ";
    }

    $aInnerqry = array();

    if(!empty($aMetaDataList))
    {
        $szQuerystr .= " Group By  $wpdb->posts.ID Having ";
        $szQuerystr .= " $wpdb->posts.ID IN (";
        $szQuerystr .= "SELECT $wpdb->postmeta.post_id FROM $wpdb->postmeta WHERE ";
        foreach($aMetaDataList as $szKey => $szValue)
        {
        $aInnerqry[] = $wpdb->prepare( "(meta_key = %s AND meta_value = %s)", $szKey, $szValue );
        }
    $szQuerystr .= implode(" OR ", $aInnerqry);
    $szQuerystr .= " GROUP BY $wpdb->postmeta.post_id ";
    $szQuerystr .= " HAVING count(*) = " . count($aMetaDataList)." ) ";
    }

    if(strtolower($orderType) == 'numerical')
      { $orderType = 'ABS'; }
    else { $orderType = ''; }

    if(!empty($aMetaDataList)) { $szQuerystr .= " ORDER BY ".$orderType."($wpdb->postmeta.meta_value) "; }
    else {  $szQuerystr .= " ORDER BY $wpdb->posts.post_date "; }

    if($orderBy == strtolower('desc')){ $szQuerystr .= " desc "; }else{ $szQuerystr .= " asc "; }

     # put limit in query built above */

    $aMetaResults = $wpdb->get_results($szQuerystr, OBJECT);

    if(!$ppp or !is_int($ppp))
    { $ppp = intval(get_query_var('posts_per_page')); } //12 posts per page you might use $ppp = intval(get_query_var('posts_per_page'));

    $wp_query->found_posts = count($aMetaResults);
    $wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp);
    $on_page = intval(get_query_var('paged'));
    if($on_page == 0){ $on_page = 1; }
    $offset = ($on_page-1) * $ppp;

    $wp_query->request = $szQuerystr." LIMIT $ppp OFFSET $offset ";
    $pageposts = $wpdb->get_results($wp_query->request, OBJECT);

    echo mysql_error();

    echo ' --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- '.$szQuerystr;

    return $pageposts;
}
?>

and the loop

<?php
if ($resultList):
//Loop through each result post to display appropriate contents
$i = 0;
foreach ($resultList as $post):
	setup_postdata($post);
        echo '<h1>'.$resultList[0]->ID.'</h1>';
endforeach;
?>

Here is the second version of this codes.

 

cambiare il from della mail di wordpress?

http://wordpress.org/support/topic/how-to-change-the-email-sender

valutazione di un sito di vino

http://www.intravino.com/primo-piano/viniamo-it-lo-smanettone-colpisce-ancora/

javascript motools

http://wall.plasm.it/examples/example-coda/

 

 

speeding open-x

But wait – there’s more. You could place banners at the bottom of your HTML page (after all content) and then use javascript to reposition the banners. What this does is give the rest of the content higher priority and it will have a better chance of being loaded first.

To help with this, please see this worked example for End of Page delivery: eop-example.

Inside the zip file is an HTML page with 2 spots for banners, as well as some fascinating content. At the bottom of the page are 2 invocation tags as well as a call to a javascript function which will reposition the 2 banners to appear above where they are meant to. The javascript file can most likely be kept as-is.

What other things can you do to help speed?

Caching is important. OpenX has built-in caching which limits calls to the database – in a production environment you might want to increase the cache time used by your installation. You might also want to install a caching system for PHP on your server.

Keep in mind what 3rd parties you are using for banners. If you are using external image banners or 3rd party HTML banners, not only must OpenX deliver the banner but the 3rd party must then deliver the image/HTML. Sometimes such external sources can be slow to load and should be kept in mind when analyzing speed.

redirect after login

A common question I’ve seen is how can you redirect a user to a specific URL after they login to WordPress. Maybe you want to hide the Admin Dashboard from your users, so redirecting them to the home page after logging in is a great way to do this. Just place the below code in your themes functions.php file:

01 <?php
02 add_action('login_form', 'redirect_after_login');
03
04 function redirect_after_login() {
05 global $redirect_to;
06 if (!isset($_GET['redirect_to'])) {
07 $redirect_to = get_option('siteurl');
08 }
09 }
10 ?>

The preceding code snippet will redirect any user who logs in to the home page (siteurl) of WordPress. You can easily set any redirect URL you want by changing the value of the $redirect_to variable. This function also verifies that the redirect_to querystring doesn’t exist before setting the redirect URL.

It’s as easy as that! Now you can easily control where your users are redirected to when they login to WordPress.

print css with table header and footer

http://csscreator.com/node/35077

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<title>Print the footer</title>
		<link rel='stylesheet' href='printfootscreen.css' type='text/css' media='screen'>
		<!--This will be only used when the page will be printed-->
		<link rel='stylesheet' href='printfootprint.css' type='text/css'  media='print'>
	</head>
	<body>
		<div id='container'>
			<!--the table below close after the closing tag of the tbody-->
			<table border='0' width='100%'>
				<!--The header will be repeated on every page-->
				<thead>
					<tr>
						<th style='width:100%'>
							This header is being repeated in all the printed pages
						</th>
					</tr>
					<tr>
						<th>
							<!--The line below the header-->
							<hr />
						</th>
					</tr>
				</thead>
				<!--Footer-->
				<tfoot>
					<tr>
						<td width='100%'>
							<table width='100%' border='0'>
								<tr>
									<td colspan='4'>
										<br />&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</tfoot>
				<tbody>
					<tr>
						<td width="100%">
						<!--------------------The page code will be placed here------------->
							<table border='0' width='80%'>
								<tr>
									<td>
										Test print page here <br />
										Test print page here <br />
										Test print page here <br />
										Test print page here <br />
									</td>
								</tr>
							</table>
						<!------------------------------------------------------------------------->
						</td>
					</tr>
				</tbody>
			</table>
			<!--the table contains the footer which will be displayed only on print media-->
			<table id="footerforprinter" width="100%">
				<tr>
					<td width="100%">
						Op al onze fakturen en offertes zijn van toepassing de 'Algemene voorwaarden Alexion Software' zoals gedeponeerd onder nummer 02061218 bij de KvK te Groningen
					</td>
				</tr>
			</table>
		</div>
		<!--the div contains the footer which will be displayed only on print media-->
		<div id='footer' >
			Op al onze fakturen en offertes zijn van toepassing de 'Algemene voorwaarden Alexion Software' zoals gedeponeerd onder nummer 02061218 bij de KvK te Groningen
		</div>
	</body>

the print css:
* {
	padding: 0;
	margin: 0;
}

#footerforprinter {
	margin-top: 16em;
	display: block;
	position: fixed;
	bottom: 0;
}

#container {
	min-height: 100%;
	width: 100%;
	margin: 0 auto;
}

* html #container {
	height: 100%;
}

#footer {
	display: none;
}

#clearfooter {
height: 50px;
}

and the screen css</html>

Sabato 28 maggio h.21.00
Drowning Dog & Dj Malatesta
from California

ingresso: 5€

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!