Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6851157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:12:49+00:00 2026-05-27T01:12:49+00:00

I have the following functions. WordPress functions, but this is really a PHP question.

  • 0

I have the following functions. WordPress functions, but this is really a PHP question. They sort my $term objects according to the artist_lastname property in each object’s metadata.

I want to pass a string into $meta in the first function. This would let me reuse this code as I could apply it to various metadata properties.

But I don’t understand how I can pass extra parameters to the usort callback. I tried to make a JS style anonymous function but the PHP version on the server is too old (v. 5.2.17) and threw a syntax error.

Any help – or a shove towards the right corner of the manual – gratefully appreciated. Thanks!

function sort_by_term_meta($terms, $meta) 
{
  usort($terms,"term_meta_cmp");
}

function term_meta_cmp( $a, $b ) 
{
    $name_a = get_term_meta($a->term_id, 'artist_lastname', true);
    $name_b = get_term_meta($b->term_id, 'artist_lastname', true);
    return strcmp($name_a, $name_b); 
}

PHP Version: 5.2.17

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:12:50+00:00Added an answer on May 27, 2026 at 1:12 am

    In PHP, one option for a callback is to pass a two-element array containing an object handle and a method name to call on the object. For example, if $obj was an instance of class MyCallable, and you want to call the method1 method of MyCallable on $obj, then you can pass array($obj, "method1") as a callback.

    One solution using this supported callback type is to define a single-use class that essentially acts like a closure type:

    function sort_by_term_meta( $terms, $meta ) 
    {
        usort($terms, array(new TermMetaCmpClosure($meta), "call"));
    }
    
    function term_meta_cmp( $a, $b, $meta )
    {
        $name_a = get_term_meta($a->term_id, $meta, true);
        $name_b = get_term_meta($b->term_id, $meta, true);
        return strcmp($name_a, $name_b); 
    } 
    
    class TermMetaCmpClosure
    {
        private $meta;
    
        function __construct( $meta ) {
            $this->meta = $meta;
        }
    
        function call( $a, $b ) {
            return term_meta_cmp($a, $b, $this->meta);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few issues with the following php functions (part of a bigger
I have the following line of code - <a href=/wordpress/wp-content/trackclicks/clickcounter.php?var=<?php echo $var3; ?> onclick=return
I have the following site structure Parent Site -> blog (wordpress) -> get-recent-posts.php ->
I have the following code: Some functions: A::A(int i_a) {cout<<int Ctor\n;} //conversion constructor void
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
I have the following dead simple elisp functions; the first removes the fill breaks
I have a class with the following member functions: /// caller pid virtual pid_t
I have the following couple of C pre-processor macros for creating test functions: //
Suppose I have the following: typedef enum functionType {ln, sin, sqrt} functionType; NSArray *functions
I have atleast 16 functions of the following form. bool Node::some_walker( Arg* arg1 )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.