Loading any Object (Entry, Page...) Based on a Custom Field Value

| No Comments | No TrackBacks |
Did you know that 'search_by_meta' is a little known method of the MT::Object class?  Until today, I didn't, but I came accros this  hidden gem today while writing a custom Perl script for one of my Movable Type installations.  Basically I needed to pull one specific page from the database based on a value that was stored in a custom field.  It seemed easy enough, and at first I tried the standard 'load' method...
Basically I tried this:

(my $page) = MT::Page->load({field.field_name => "somevalue"});

As I already suspected, this did not work.  After some searching with Google I came accross this little forum posting, which held the key.  This code works:

my $mt = MT->instance();
(my $page) = MT::Page->search_by_meta('field.field_name', 'somevalue');

Shame the documentation for this incredibly useful method is hidden in an obscure part of the documentation that is not easily findable through Google.

No TrackBacks

TrackBack URL: http://www.movabletips.com/cgi-bin/mt/mt-tb.cgi/31

Leave a comment


Movable Type Help?

"Can my Movable Type issue or project be taken care of by a professional?" Yes It Can Be! Contact YesItCan.be

Tags

Powered by Movable Type 5.2.7