[wp-hackers] query_posts orderby=meta_value

Ash Goodman ash at thinkinginvain.com
Tue Feb 9 06:06:45 UTC 2010


Hi all, I wonder if anyone can tell me: according to this page in the codex:
http://codex.wordpress.org/Template_Tags/query_posts in the section "Orderby
Parameters" I should be able to order the resulting posts from a custom
query (orderby=meta_value - Note: A meta_key=keyname must also be present in
the query. )

So for example I would have a query with the following parameters:
"post_type=page&posts_per_page=5&meta_key=order" and then I would specify
the meta_value=

And thats where it breaks down for me as If I specify a specific meta_value
how exactly would ordering be achieved? if all the posts ahd the same
meta_value wouldn't the ordering just fall back to default?

I am sure I am just not grasping what's happening correctly and would
welcome anyone's help in getting my thick head round this.

Thanks!

Ash

On 9 February 2010 03:56, <wp-hackers-request at lists.automattic.com> wrote:

> Send wp-hackers mailing list submissions to
>        wp-hackers at lists.automattic.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://lists.automattic.com/mailman/listinfo/wp-hackers
> or, via email, send a message with subject or body 'help' to
>        wp-hackers-request at lists.automattic.com
>
> You can reach the person managing the list at
>        wp-hackers-owner at lists.automattic.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of wp-hackers digest..."
>
>
> Today's Topics:
>
>   1. Re: Plugins: Best practice for conditional loading of     actions
>      and file includes (Otto)
>   2. Re: Plugins: Best practice for conditional loading of     actions
>      and file includes (Otto)
>   3. howto including full path in javascript file. (Bjorn Wijers)
>   4. Re: howto including full path in javascript file.
>      (Mitch Canter | studionashvegas)
>   5. Re: howto including full path in javascript file. (Chris Scott)
>   6. Re: howto including full path in javascript file.
>      (tunamaxx at yahoo.com)
>   7. Re: howto including full path in javascript file. (Hikari)
>   8. Re: howto including full path in javascript file. (Otto)
>   9. Re: howto including full path in javascript file. (logikal16)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 8 Feb 2010 10:47:15 -0600
> From: Otto <otto at ottodestruct.com>
> Subject: Re: [wp-hackers] Plugins: Best practice for conditional
>        loading of      actions and file includes
> To: wp-hackers at lists.automattic.com
> Message-ID:
>        <161617691002080847r3df5dea8q215e852a4638e726 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Fri, Feb 5, 2010 at 4:20 PM, Ozh <ozh at planetozh.com> wrote:
> > On Fri, Feb 5, 2010 at 9:48 PM, Otto <otto at ottodestruct.com> wrote:
> >> So, best practice: Keep hooks near the functions they are hooking. If
> >> you don't like the way that looks, then at least keep them in the same
> >> file.
> >
> > I prefer grouping all the hooks at the same place instead of spreading
> > them all across the file(s), because having them in one place makes it
> > easier in one glance to understand the flow of things and what happens
> > when.
> >
> > This said, I don't think the location of the hooks (near their
> > functions or all grouped in one place) is a matter of "best practice"
> > (assuming they're correctly declared in both case of course)
>
> Let's just say that you're far less likely to accidentally add a hook
> to an undeclared function if you have the hook and the function right
> next to each other.
>
> -Otto
> Sent from Memphis, TN, United States
>
>
> ------------------------------
>
> Message: 2
> Date: Mon, 8 Feb 2010 10:48:35 -0600
> From: Otto <otto at ottodestruct.com>
> Subject: Re: [wp-hackers] Plugins: Best practice for conditional
>        loading of      actions and file includes
> To: wp-hackers at lists.automattic.com
> Message-ID:
>        <161617691002080848k602e78d9g3e585cbcfa58a554 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Sat, Feb 6, 2010 at 10:03 AM, Ade Walker <photofantaisie at gmail.com>
> wrote:
> > 2010/2/5 Otto <otto at ottodestruct.com>
> >
> >> Both, actually. No plugin should *ever* load wp-load directly. It's
> >> never, ever, necessary; it's sloppy programming style; and it's bad
> >> practice. However, it is often quick and easy to understand for some
> >> authors, so it does happen a fair amount. Still, it shouldn't be
> >> there, and any plugin you find with it should be fixed to not require
> >> it any more.
> >>
> >> Feel free to pass anybody you find doing this my email, and I'll tell
> >> them how to fix their plugin. :)
> >>
> >
> > Would you care to share on this list? Or can I contact you off line?
>
> Just email me directly if you want more info on this sort of thing. I
> don't hide my email address. :)
>
> Actually, this comes up so often that I might make a blog post about it.
>
> -Otto
> Sent from Memphis, TN, United States
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 08 Feb 2010 18:45:55 +0100
> From: Bjorn Wijers <burobjorn at gmail.com>
> Subject: [wp-hackers] howto including full path in javascript file.
> To: wp-hackers at lists.automattic.com
> Message-ID: <4B704DD3.8000909 at gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> Hi,
>
> I was wondering what other people use to include full paths in their
> theme javascript files and keep it dynamic (so no hardcoded paths!). For
> instance I would like to call some images in my javascript file and I
> need to use a full path. What would be the best practice for this?
>
> Thanks,
>
> grtz
> BjornW
>
> --
>
> met vriendelijke groet,
> Bjorn Wijers
>
> * b u r o b j o r n .nl *
> digitaal vakmanschap | digital craftsmanship
>
> Concordiastraat 68-126
> 3551 EM Utrecht
> The Netherlands
>
> phone: +31 6 49 74 78 70
> http://www.burobjorn.nl
>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 8 Feb 2010 11:57:10 -0600
> From: "Mitch Canter | studionashvegas" <mitch at studionashvegas.com>
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: <wp-hackers at lists.automattic.com>
> Message-ID: <000901caa8e8$26ec7470$74c55d50$@com>
> Content-Type: text/plain;       charset="us-ascii"
>
> One of two options works - if you are keeping the javascript files in your
> root directory, prepend the urls with <?php bloginfo('siteurl'); ?>.  If
> you're doing it only within your template, use <?php
> bloginfo('template_directory'); ?>
>
> Example:
>
> src="<?php bloginfo('siteurl'); ?>/js/thickbox.js"
>
> or
>
> <img src="<?php bloginfo('siteurl'); ?>/js/img/thickbox.jpg">
>
> Good for linking to images too.
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Bjorn Wijers
> Sent: Monday, February 08, 2010 11:46 AM
> To: wp-hackers at lists.automattic.com
> Subject: [wp-hackers] howto including full path in javascript file.
>
> Hi,
>
> I was wondering what other people use to include full paths in their
> theme javascript files and keep it dynamic (so no hardcoded paths!). For
> instance I would like to call some images in my javascript file and I
> need to use a full path. What would be the best practice for this?
>
> Thanks,
>
> grtz
> BjornW
>
> --
>
> met vriendelijke groet,
> Bjorn Wijers
>
> * b u r o b j o r n .nl *
> digitaal vakmanschap | digital craftsmanship
>
> Concordiastraat 68-126
> 3551 EM Utrecht
> The Netherlands
>
> phone: +31 6 49 74 78 70
> http://www.burobjorn.nl
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
>
> ------------------------------
>
> Message: 5
> Date: Mon, 8 Feb 2010 13:40:50 -0500
> From: Chris Scott <cjscott69 at gmail.com>
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: wp-hackers at lists.automattic.com
> Message-ID:
>        <469fb3cc1002081040u2635e691taee286b67e91c57e at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Mon, Feb 8, 2010 at 12:45 PM, Bjorn Wijers <burobjorn at gmail.com> wrote:
> > Hi,
> >
> > I was wondering what other people use to include full paths in their
> > theme javascript files and keep it dynamic (so no hardcoded paths!). For
> > instance I would like to call some images in my javascript file and I
> > need to use a full path. What would be the best practice for this?
>
> You can add an action to wp_head to set a js var that is the URL to
> your site (e.g. using bloginfo('siteurl')). Make sure this action runs
> at a higher priority than your other js if you aren't putting them in
> the footer so the var is available to your scripts.
>
> --
> Chris Scott
> http://iamzed.com/
> http://hailtheale.com/
>
> >
> > Thanks,
> >
> > grtz
> > BjornW
> >
> > --
> >
> > met vriendelijke groet,
> > Bjorn Wijers
> >
> > * b u r o b j o r n .nl *
> > digitaal vakmanschap | digital craftsmanship
> >
> > Concordiastraat 68-126
> > 3551 EM Utrecht
> > The Netherlands
> >
> > phone: +31 6 49 74 78 70
> > http://www.burobjorn.nl
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
>
>
> ------------------------------
>
> Message: 6
> Date: Mon, 8 Feb 2010 18:43:58 +0000
> From: tunamaxx at yahoo.com
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: wp-hackers at lists.automattic.com
> Message-ID:
>
>  <485788465-1265654649-cardhu_decombobulator_blackberry.rim.net-1753816410- at bda161.bisx.prod.on.blackberry
> >
>
> Content-Type: text/plain
>
> I think the OP was asking how to use the full path INSIDE javascripts, not
> how to include them in themes.
>
> I'd like to know how to do this as well. Could you create a var in a script
> in the head that contained the path as instructed by Mitch, and then use the
> value of that var in the included script?
>
> Thanks,
>
> Tony
>
> ------Original Message------
> From: Mitch Canter | studionashvegas
> Sender: wp-hackers-bounces at lists.automattic.com
> To: wp-hackers at lists.automattic.com
> ReplyTo: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] howto including full path in javascript file.
> Sent: Feb 8, 2010 9:57 AM
>
> One of two options works - if you are keeping the javascript files in your
> root directory, prepend the urls with <?php bloginfo('siteurl'); ?>.  If
> you're doing it only within your template, use <?php
> bloginfo('template_directory'); ?>
>
> Example:
>
> src="<?php bloginfo('siteurl'); ?>/js/thickbox.js"
>
> or
>
> <img src="<?php bloginfo('siteurl'); ?>/js/img/thickbox.jpg">
>
> Good for linking to images too.
>
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Bjorn Wijers
> Sent: Monday, February 08, 2010 11:46 AM
> To: wp-hackers at lists.automattic.com
> Subject: [wp-hackers] howto including full path in javascript file.
>
> Hi,
>
> I was wondering what other people use to include full paths in their
> theme javascript files and keep it dynamic (so no hardcoded paths!). For
> instance I would like to call some images in my javascript file and I
> need to use a full path. What would be the best practice for this?
>
> Thanks,
>
> grtz
> BjornW
>
> --
>
> met vriendelijke groet,
> Bjorn Wijers
>
> * b u r o b j o r n .nl *
> digitaal vakmanschap | digital craftsmanship
>
> Concordiastraat 68-126
> 3551 EM Utrecht
> The Netherlands
>
> phone: +31 6 49 74 78 70
> http://www.burobjorn.nl
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> ------------------------------
>
> Message: 7
> Date: Mon, 8 Feb 2010 17:23:32 -0200
> From: "Hikari" <lists at hikarinet.info>
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: <wp-hackers at lists.automattic.com>
> Message-ID: <F2EE14C48088442EA9F820CEC5F71700 at MAIN>
> Content-Type: text/plain;       charset="iso-8859-1"
>
> I've needed that once too :)
>
>
> Let's say you add your script:
>
>
>
> <?php
> add_action('wp_print_scripts', 'prefix_scriptAction');
>
> function prefix_scriptAction(){
>    wp_enqueue_script('prefix_js', plugin_dir_url(__FILE__).'myjs.js');
> }
> ?>
>
>
>
> First of all, you should avoid running your script just during the page
> load, because if you do so you'll make the page load slowly.
> Use the 'onload' event or add it to the footer ('wp_print_footer_scripts'
> action).
>
> Either way, use a JavaScript variable to store the path to your plugin's
> root folder. This variable should be present when your
> script needs it, so if your script runs after or just after the page load,
> I believe you can use the 'wp_print_scripts' action to
> add the variable to the header. Just change the previous function to
> include it.
>
>
>
> <?php
> add_action('wp_print_scripts', 'prefix_scriptAction');
>
> function prefix_scriptAction(){
>    wp_enqueue_script('prefix_js', plugin_dir_url(__FILE__).'myjs.js');
>
> ?>
>
> <script type="text/javascript">
>    var prefix_path = <?php echo plugin_dir_url(__FILE__); ?>;
> </script>
>
> <?php
> }
> ?>
>
>
> I didn't test the code, but it's an exemple. This way, your script can try
> for 'prefix_path', and if the code is right it will store
> the URL path to your plugin's root folder, and using it you can append
> subfolders and files, having access to what you want.
>
>
> I've already used a proprietary dropdown menu that its JS considered it
> would be always used in homepage, and when it run inside
> posts and other resources its images were being deleted, because they
> weren't where the script was expecting :P
>
>
> ---------------------------
> Hikari -  A Luz ilumina a PAZ
> http://Hikari.ws
> http://ConscienciaPlanetaria.com
>
> Tenha seu pr?prio email meunome @ ConscienciaPlanetaria.com.br!:
> http://seunome.ConscienciaPlanetaria.com.br
>
>
>
> ------------------------------
>
> Message: 8
> Date: Mon, 8 Feb 2010 13:36:08 -0600
> From: Otto <otto at ottodestruct.com>
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: wp-hackers at lists.automattic.com
> Message-ID:
>        <161617691002081136k33409a40h662fb1c22bec378 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Mon, Feb 8, 2010 at 11:45 AM, Bjorn Wijers <burobjorn at gmail.com> wrote:
> > I was wondering what other people use to include full paths in their
> > theme javascript files and keep it dynamic (so no hardcoded paths!). For
> > instance I would like to call some images in my javascript file and I
> > need to use a full path. What would be the best practice for this?
>
> Best way in a plugin:
>
> add_action('wp_print_scripts','myscript');
> function myscript() {
> ?>
> <script type="text/javascript">
>   var my_plugin_url = <?php echo plugin_dir_url(__FILE__); ?>;
> </script>
> <?php
> }
>
> This will get put into the page before your enqueued scripts, so the
> variable will be defined and available for them to use.
>
> You can use this same basic approach to pass along other settings to
> javascripts as well. In fact, the admin side of things does it for
> you. Look at the source of an admin page, and notice the handy
> userSettings array, as well as the ajaxurl variable.
>
>
> -Otto
> Sent from Memphis, TN, United States
>
>
> ------------------------------
>
> Message: 9
> Date: Mon, 8 Feb 2010 11:56:29 -0800 (PST)
> From: logikal16 <logikal16 at gmail.com>
> Subject: Re: [wp-hackers] howto including full path in javascript
>        file.
> To: wp-hackers at lists.automattic.com
> Message-ID:
>        <ff0a102d-83ac-46a0-99fd-10995aa490b8 at j1g2000vbl.googlegroups.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> <script type="text/javascript">
> var mypath = "<?php echo WP_CONTENT_URL; ?>/img/somefile.gif";
> // more javascript code
> // you could also use the WP_PLUGIN_URL constant
> </script>
>
> I keep as much stuff in "wp-content" as possible (instead of the site
> root). This isn't for everything (robots.txt, sitemap.xml.gz), but it
> keeps all of the custom files together, making any updates/migrations
> a bit simpler.
>
> Matt
>
> On Feb 8, 2:36?pm, Otto <o... at ottodestruct.com> wrote:
> > On Mon, Feb 8, 2010 at 11:45 AM, Bjorn Wijers <burobj... at gmail.com>
> wrote:
> > > I was wondering what other people use to include full paths in their
> > > theme javascript files and keep it dynamic (so no hardcoded paths!).
> For
> > > instance I would like to call some images in my javascript file and I
> > > need to use a full path. What would be the best practice for this?
> >
> > Best way in a plugin:
> >
> > add_action('wp_print_scripts','myscript');
> > function myscript() {
> > ?>
> > <script type="text/javascript">
> > ? ?var my_plugin_url = <?php echo plugin_dir_url(__FILE__); ?>;
> > </script>
> > <?php
> >
> > }
> >
> > This will get put into the page before your enqueued scripts, so the
> > variable will be defined and available for them to use.
> >
> > You can use this same basic approach to pass along other settings to
> > javascripts as well. In fact, the admin side of things does it for
> > you. Look at the source of an admin page, and notice the handy
> > userSettings array, as well as the ajaxurl variable.
> >
> > -Otto
> > Sent from Memphis, TN, United States
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hack... at lists.automattic.comhttp://
> lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> ------------------------------
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
> End of wp-hackers Digest, Vol 61, Issue 24
> ******************************************
>


More information about the wp-hackers mailing list