• wdlyons

    (@wdlyons)


    Hi,

    I am creating a small plugin shortcode which appears to work ok except the number 1 appears below the output

    This is the code I am using to extract the data from the wp database table and wish to display on a wordpress page.

    global $wpdb;
    
    $result = $wpdb->get_row ( 'SELECT * FROM wp_lb_person WHERE id = "'.$id.'"'); 
    
    echo $result->first_name. " " . $result->family_name. "<br />";
    
    echo $result->date_of_birth."<br />";
    echo $result->date_of_death."<br />";

    The output to the page is below

    David Lyons
    02/02/2001
    02/02/2001
    1

    Any ideas would be appreciated

    Regards

    Warwick

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael

    (@alchymyth)

    a: shortcode functions should return the value, not echo it; https://codex.www.ads-software.com/Shortcode_API

    b: what is the full code?

    Thread Starter wdlyons

    (@wdlyons)

    Hi Thanks for your reply

    function pedigree() {

    `global $wpdb;

    $result = $wpdb->get_row ( ‘SELECT * FROM wp_lb_person WHERE id = “‘.$id.'”‘);

    echo $result->first_name. ” ” . $result->family_name. “<br />”;

    echo $result->date_of_birth.”<br />”;
    echo $result->date_of_death.”<br />”;

    }

    add_shortcode(‘add-pedigree’, ‘pedigree’); `

    David Lyons
    02/02/2001
    02/02/2001
    1 <- This appears My Query is how do I stop it from appearing

    Thanks again for your reply

    Michael

    (@alchymyth)

    is there any other code in the plugin?

    how is the shortcode used in a post?

    does the number appear whereever you use the shortcode?

    can you post a live link to the problem?

    Thread Starter wdlyons

    (@wdlyons)

    Hi,

    I will forward the details on shortly.
    I have been playing around myself and have stuffed it up somehow. I can no longer get anything working. As soon as I do i will post the answers to your questions here.

    Again Thanks for your help

    Warwick

    Thread Starter wdlyons

    (@wdlyons)

    Wouldn’t you know it.

    As soon as I posted the previous post I got it to work!!!

    Ok here is how I have it.

    The plugin creates a menu page with a form to allow person info to be inserted into the database. It also creates a new page with the shortcode [pedigree id = “‘ . $id . ‘”] automatically inserted with the person id :

    <?php
    $strSql = 'select last_insert_id() as lastId';
      $result = mysql_query($strSql);
      while($row = @mysql_fetch_assoc($result)){
              $id = $row['lastId'];
      }
    
    $new_post = array(
    'post_title' => $id. " " . $first_name . " " . $family_name,
    'post_content' => '[pedigree id = "' . $id . '"]',
    'post_status' => 'publish',
    'post_author' => $user_ID,
    'post_type' => 'page',
    'post_category' => array(0)
    );
    $post_id = wp_insert_post($new_post, $wp_error );
    echo $post_id
    ?>

    I have a shortcode.php file which I store the shortcodes functions. This file is included into install.php file which has the wordpress header comments for the plugin.

    shortcode.php

    <?php
    function pedigree($atts) {
    	extract(shortcode_atts( array(
    		'id' => ' ',
    	), $atts ) );
    
    	return include ('addin-pedigree.php');
    
    }
    
    add_shortcode('pedigree', 'pedigree');
    
    ?>

    I then use a file called addin-pedigree.php to hold the code:

    addin-pedigree.php

    <?php
    
    global $wpdb;
    
    $result = $wpdb->get_row ( 'SELECT * FROM wp_lb_person WHERE id = "'.$id.'"'); 
    
    echo $result->first_name. " " . $result->family_name. "<br />";
    
    echo $result->date_of_birth. "<br />";
     echo $result->date_of_death. "<br />";
    ?>

    This appears to run ok and it displays the correct information, but the number one appears below it.

    John Barton
    01/01/2001
    01/01/2001
    1 <- This is the problem

    Live Page: https://lyons-barton.com/17-john-barton/

    The shortcode that is used is [pedigree id = “17”] (Derived from [pedigree id = “‘ . $id . ‘”])

    I hope this answers your question (and is not to confusing)

    Thanks

    Warwick

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Number keeps appearing below plugin shortcode output’ is closed to new replies.