0

So, here is original function which does not have any parameters (wordpress)

public static function getCurrent() {
    $post = get_post();
    $profiles = new MY_images($post->ID);
    return $profiles;
}

which is used in the following variable:

$my_site_images = MY_images::getCurrent();

So, it gets the $post->ID from the getCurrent()

Now, I want to customize it so that I can add any id in it or leave it empty for default function such as following:

$my_site_images = MY_images::getCurrent(343);  (where the "post id" is 343)

What modification do I need to make to the original function in order for me to add any ID in it??

Thanks bunch!

1 Answer 1

3

You can choose to pass it a post id or leave it blank to get the current post id.

public static function getCurrent($post_id=false) {
    if($post_id !== false) {
        $profiles = new MY_images($post_id);
    } else {
        $post = get_post();
        $profiles = new MY_images($post->ID);
    }
    return $profiles;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.