0

I wanted to load my custom plugin when the "Jobs" page is loaded. How am I able to do it? This is my code so far.

<?php

/**
 * Plugin Name: wp-retrieve-database
 * Description: retrieves data from the database.
 * Version: 0.5
 * Author: Chan */

global $wpdb;
$table_name = $wpdb->prefix . "Careers";
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
    function get_scrapy_scraped(){
    <table border="1">
    <tr>
    <th>Job Name</th>
    <th>Location/Dept</th>
    <th>Complete Info</th>
    <th>Application Link<th>
    </tr>
        foreach ($retrieve_data as $retrieved_data){
        <tr>
        <td>echo $retrieved_data->Job_Name;</td>
        <td>echo $retrieved_data->Job_Department;</td>
        <td>echo $retrieved_data->Job_Link_Info;</td>
        <td>echo $retrieved_data->Job_Link_Apply;</td>
        </tr>
        }
    </table>
    }
add_action('dont know what to be used', 'get_scrapy_scraped');  
?>
2
  • Where is the jobs page, in the front or admin, how is it loaded?
    – Wyck
    Oct 1, 2013 at 5:57
  • Im kinda new to worpress but this is the site... southjerseyrn.com/jobs
    – chano
    Oct 1, 2013 at 5:59

1 Answer 1

1

Filter the_content and check if is_page( 'jobs' ) is TRUE:

add_filter( 'the_content', 'get_scrapy_scraped' );

function get_scrapy_scraped( $content )
{
    global $wpdb;

    if ( ! is_page( 'jobs' ) )
        return $content;

    $table_name    = $wpdb->prefix . "Careers";
    $retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );

    if ( ! $retrieve_data )
        return $content;

    $table = '<table><tr>
    <th>Job Name</th>
    <th>Location/Dept</th>
    <th>Complete Info</th>
    <th>Application Link<th>
    </tr>';

    foreach ( $retrieve_data as $row )
    {
        $table .= "<tr>
            <td>{$row->Job_Name}</td>
            <td>{$row->Job_Department}</td>
            <td>{$row->Job_Link_Info}</td>
            <td>{$row->Job_Link_Apply}</td>
            </tr>";
    }

    $table .= "</table>";

    return $table . $content;
}
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.