How can I create a function to use inside a while loop. Like the_title()
or the_meta()
in WordPress?
A simple sample is enough.
Leave a Reply
You must be logged in to post a comment.
How can I create a function to use inside a while loop. Like the_title()
or the_meta()
in WordPress?
A simple sample is enough.
You must be logged in to post a comment.
you could use globals. For example, assuming you have a global array, here is something that does that (obviously you need to add more robustness such a error checking. plus how you would use this on wordpress would depend on what you are doing)
So from looking at the
the_title()
and related functions, it looks like you should be able to do as follows (untested, but should work):If you don’t specify any post_id to the function,
get_post()
will retrieve the current post in the loop for you to use in your function.