Query API

You can get things for the history by using the class SimpleHistoryLogQuery.

A quick example that displays the latest 5 rows from the log:


function simple_history_test_output() {
    $log_query = new \Simple_History\Log_Query;
    $simple_history = \Simple_History\Simple_History::get_instance();

    $query_results = $log_query->query( [
        'posts_per_page' => 5,
    ] );

    printf(
        '
            <p>Found %1$d rows.</p>
            <p>Viewing page %2$d of %3$d.</p>
        ',
        esc_html( $query_results['total_row_count'] ), // 1
        esc_html( $query_results['page_current'] ), // 2
        esc_html( $query_results['pages_count'] ), // 3
    );

    echo "<ul>";
    
    foreach ( $query_results['log_rows'] as $row ) {
        $header_output = $simple_history->getLogRowHeaderOutput( $row );
        $text_output = $simple_history->getLogRowPlainTextOutput( $row );
        $details_output = $simple_history->getLogRowDetailsOutput( $row );

        echo "<li>";
        echo "<hr />";
        echo "<p>{$header_output}</p>";
        echo "<p>{$text_output}</p>";
        echo "<p>{$details_output}</p>";
        echo "</li>";
    }
    
    echo "</ul>";
}

Code language: PHP (php)

When running the above function the output will look something like this:

simple-history-log-query-example