Forums

Writing plugin question (1 post)

  1. doodlebee
    Member
    Posted 4 years ago #

    Had a quick question here - this is just a basic thing that I can't find.

    I'm looking to write a custom function. I have a database query that I want to use for several different purposes - so rather than calling in the database query over and over again to spit out the alternate output, I wanted to just use the *same* query and add things (like hooks or filters? I think?) and create different outputs with the data I'm retrieving.

    I can't seem to get the syntax right. What I have so far is this:

    $query = ("SELECT stuff FROM tables WHERE rows do this stuff");
    
    $query_data = $wpdb->get_row($query, ARRAY_A);
    //make my list of varibles here

    Now, I wanted to turn this into a function...so something like:

    function get_query_stuff() {
    //put the above example code in this spot
    
    //put in formatted output here
    }

    However, like I said, this works *great* for displaying the specified formatted output by adding the <?php get_query_stuff();?> into a template file. It'll display exactly what I want.

    But I'd like to do something else where it's more like:

    function get_query_stuff($tag1, $tag2, $tag3) {
    // example code - the actual query and variables - here
    
    $tag1 = variable stuff output in a certain way here
    $tag2 = other stuff in a different format
    $tag3 = more stuff in yet another format
    }

    I'm new to this plugin stuff, and of course the above isn't working for crap. So I was hoping someone could give me a rough outline of the structure to achieve what I want. I'd like to just be able to insert something like <?php get_query_stuff('tag1'); ?> into my template file so it'll display the output for $tag1 - but it's just not going. I've tried looking at other plugins - but I think what *I* am looking for is a little more basic than the stuff I have, and I can't seem to wrap my head around it by looking at the complicated plugins. I don't even know the exact terminology I'm looking for, so my search results are hit-or-miss.

    So can someone pass me a really simple example of how to do this? I don't need code to perform a specific thing, I just want to know a basic layout to accomplish this. I've tried reading the codex on hooks and filters - but it doesn't provide any examples (that I can find) on inserting multiple variables into *one* function - I can add filters to wp_meta() and such, but I want to add the filter directly into the function I'm writing, and then call it in later.

    Hope I'm not too confusing! Any help is appreciated :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.