Cdx transcription factors have crucial roles in anteroposterior patterning of the nervous system and mesoderm. Here we focus on the role of cdx4 in patterning the endoderm in zebrafish. We show that cdx4 has roles in determining pancreatic beta-cell number, directing midline convergence of beta-cells during early pancreatic islet formation, and specifying the anteroposterior location of foregut organs. Embryos deficient in cdx4 have a posteriorly shifted pancreas, liver and small intestine. The phenotype is more severe with knockdown of an additional Cdx factor, cdx1a. We show that cdx4 functions within the endoderm to localize the pancreas. Morpholino knockdown of cdx4 specifically in the endoderm recapitulates the posteriorly shifted pancreas observed in cdx4 mutants. Conversely, overexpression of cdx4 specifically in the endoderm is sufficient to shift the pancreas anteriorly. Together, these results suggest a model in which cdx4 confers posterior identity to the endoderm. Cdx4 might function to block pancreatic identity by preventing retinoic acid (RA) signal transduction in posterior endoderm. In support of this, we demonstrate that in cdx4-deficient embryos treated with RA, ectopic beta-cells are located well posterior to the normal pancreatic domain.