{"id":1497,"date":"2014-02-03T10:30:02","date_gmt":"2014-02-03T10:30:02","guid":{"rendered":"http:\/\/musilda.cz\/?p=1497"},"modified":"2014-02-03T10:30:02","modified_gmt":"2014-02-03T10:30:02","slug":"funkce-get_post","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/funkce-get_post\/","title":{"rendered":"Funkce get_post"},"content":{"rendered":"<p>Dal\u0161\u00ed funkc\u00ed, kterou se budu v Codexu zab\u00fdvat, je get_post. Jedn\u00e1 se o jednoduchou funkci, kter\u00e1 v\u00e1m na z\u00e1klad\u011b id, vr\u00e1t\u00ed cel\u00fd \u010dl\u00e1nek. Pokud nebudete specifikovat formu vr\u00e1cen\u00fdch informac\u00ed, dostanete k dispozici object.<!--more--><\/p>\n<h2>Pou\u017eit\u00ed<\/h2>\n<pre lang=\"php\">get_post( $id, $output, $filter );<\/pre>\n<h2>Parametry<\/h2>\n<p><strong>$id<\/strong> &#8211; \u010d\u00edslo, nebo object, z\u00e1le\u017e\u00ed na tom, jak jste id \u010dl\u00e1nku z\u00edskali, \u010dasto je vid\u011bt $post-&gt;ID<\/p>\n<p><strong>$output<\/strong> &#8211; tvar, v jak\u00e9m se vr\u00e1t\u00ed hodnota, m\u016f\u017ee b\u00fdt:<\/p>\n<ul>\n<li>OBJECT<\/li>\n<li>ARRAY_A<\/li>\n<li>ARRAY_N<\/li>\n<\/ul>\n<p>Defaultn\u00ed je OBJECT, pokud pou\u017eijete ARRAY_A, dostanete asociativn\u00ed pole, ARRAY_N, pole s \u010d\u00edseln\u00fdmi kl\u00ed\u010di.<br \/>\nV praxi to znamen\u00e1, \u017ee pokud $output nepou\u017eijete, m\u016f\u017eete pou\u017e\u00edt hodnoty $my_post-&gt;post_content, v p\u0159\u00edpad\u011b pole ARRAY_A m\u016f\u017eete pou\u017e\u00edt $my_post[&#8218;post_content&#8216;].<\/p>\n<p><strong>$filter<\/strong> &#8211; defaultn\u00ed je post filtr <strong>raw<\/strong>, co\u017e definuje, jak\u00fdm zp\u016fsobem bude WordPress sanitovat (nep\u0159i\u0161el jsem na to jak nejl\u00e9pe p\u0159elo\u017eit sanitize) vr\u00e1cen\u00e1 data. M\u016f\u017ee se hodit, pokud budete hodnoty ukladat do datab\u00e1ze a budete se cht\u00edt zabezpe\u010dit proti podstr\u010den\u00ed.<\/p>\n<p>Mo\u017en\u00e9 hodnoty $filter:<\/p>\n<ul>\n<li>raw<\/li>\n<li>edit<\/li>\n<li>db<\/li>\n<li>display<\/li>\n<li>attribute<\/li>\n<li>js<\/li>\n<\/ul>\n<h2>P\u0159\u00edklady:<\/h2>\n<pre lang=\"php\">\n$my_post = get_post($post-&gt;ID);\necho '<h1>'.$my_post-&gt;post_title.'<\/h1>';\necho '<div class=\"entry-content\">'.$my_post-&gt;post_content.'<\/div>';\n<\/pre>\n<p><strong>Obdobn\u011b:<\/strong><\/p>\n<pre lang=\"php\">\n$my_post = get_post($post-&gt;ID,ARRAY_A);\necho '<h1>'.$my_post['post_title'].'<\/h1>';\necho '<div class=\"entry-content\">'.$my_post['post_content'].'<\/div>';\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dal\u0161\u00ed funkc\u00ed, kterou se budu v Codexu zab\u00fdvat, je get_post. Jedn\u00e1 se o jednoduchou funkci, kter\u00e1 v\u00e1m na z\u00e1klad\u011b id, vr\u00e1t\u00ed cel\u00fd \u010dl\u00e1nek. Pokud nebudete specifikovat formu vr\u00e1cen\u00fdch informac\u00ed, dostanete k dispozici object.<\/p>\n","protected":false},"author":1,"featured_media":8523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","footnotes":""},"categories":[7,22],"tags":[],"class_list":["post-1497","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codex","category-template-tags"],"acf":[],"uagb_featured_image_src":{"full":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu.png",1200,800,false],"thumbnail":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu-150x150.png",150,150,true],"medium":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu-300x200.png",300,200,true],"medium_large":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu-768x512.png",640,427,true],"large":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu-1024x683.png",640,427,true],"1536x1536":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu.png",1200,800,false],"2048x2048":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu.png",1200,800,false],"archive-list":["https:\/\/affinite.io\/cs\/wp-content\/uploads\/sites\/2\/2014\/12\/funkce-ve-wordpressu-400x265.png",400,265,true]},"uagb_author_info":{"display_name":"Affinite","author_link":"https:\/\/affinite.io\/cs\/author\/affinite\/"},"uagb_comment_info":0,"uagb_excerpt":"Dal\u0161\u00ed funkc\u00ed, kterou se budu v Codexu zab\u00fdvat, je get_post. Jedn\u00e1 se o jednoduchou funkci, kter\u00e1 v\u00e1m na z\u00e1klad\u011b id, vr\u00e1t\u00ed cel\u00fd \u010dl\u00e1nek. Pokud nebudete specifikovat formu vr\u00e1cen\u00fdch informac\u00ed, dostanete k dispozici object.","_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/8523"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}