{"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":"

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

Pou\u017eit\u00ed<\/h2>\n
get_post( $id, $output, $filter );<\/pre>\n

Parametry<\/h2>\n

$id<\/strong> – \u010d\u00edslo, nebo object, z\u00e1le\u017e\u00ed na tom, jak jste id \u010dl\u00e1nku z\u00edskali, \u010dasto je vid\u011bt $post->ID<\/p>\n

$output<\/strong> – tvar, v jak\u00e9m se vr\u00e1t\u00ed hodnota, m\u016f\u017ee b\u00fdt:<\/p>\n

    \n
  • OBJECT<\/li>\n
  • ARRAY_A<\/li>\n
  • ARRAY_N<\/li>\n<\/ul>\n

    Defaultn\u00ed je OBJECT, pokud pou\u017eijete ARRAY_A, dostanete asociativn\u00ed pole, ARRAY_N, pole s \u010d\u00edseln\u00fdmi kl\u00ed\u010di.
    \nV praxi to znamen\u00e1, \u017ee pokud $output nepou\u017eijete, m\u016f\u017eete pou\u017e\u00edt hodnoty $my_post->post_content, v p\u0159\u00edpad\u011b pole ARRAY_A m\u016f\u017eete pou\u017e\u00edt $my_post[‚post_content‘].<\/p>\n

    $filter<\/strong> – defaultn\u00ed je post filtr 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

    Mo\u017en\u00e9 hodnoty $filter:<\/p>\n

      \n
    • raw<\/li>\n
    • edit<\/li>\n
    • db<\/li>\n
    • display<\/li>\n
    • attribute<\/li>\n
    • js<\/li>\n<\/ul>\n

      P\u0159\u00edklady:<\/h2>\n
      \n$my_post = get_post($post->ID);\necho '

      '.$my_post->post_title.'<\/h1>';\necho '
      '.$my_post->post_content.'<\/div>';\n<\/pre>\n

      Obdobn\u011b:<\/strong><\/p>\n

      \n$my_post = get_post($post->ID,ARRAY_A);\necho '

      '.$my_post['post_title'].'<\/h1>';\necho '
      '.$my_post['post_content'].'<\/div>';\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

      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":{"rank_math_lock_modified_date":false,"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"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/1497"}],"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}]}}