Problem is within function query_abstract_post_table
where you have '$ids'
wrapped in single quotes:
Problem:
$sql = "SELECT * FROM $table_name WHERE ID NOT IN ('$ids')";
In the above example, only the first ID returned in the concatenated string (from the array) will be recognized by the NOT IN
clause.
Solution:
$sql = "SELECT * FROM $table_name WHERE ID NOT IN ($ids)";